Ehi Habr!
Recentemente aghju vistu una versione scaricata di u flussu di prugrammazione "Cumu creà a vostra propria applicazione web in Flask". E aghju decisu di cunsulidà a mo cunniscenza in qualchì prughjettu. Per un bellu pezzu ùn sapia micca ciò chì scrive è l'idea hè vinuta à mè: "Perchè ùn fate micca una mini-backdoor in Flask?"
I primi opzioni per implementazioni è capacità di u backdoor apparsu immediatamente in a mo testa. Ma aghju decisu di fà immediatamente una lista di capacità backdoor:
- Sapete cumu apre i siti web
- Avè accessu à a linea di cummanda
- Puderete apre prugrammi, foto, video
Dunque, u primu puntu hè estremamente faciule da implementà cù u modulu di u navigatore web. Aghju decisu di implementà u sicondu puntu cù u modulu os. È u terzu hè ancu attraversu u modulu os, ma aghju aduprà "ligami" (più nantu à questu dopu).
Scrive un servitore
Allora, *drumroll* tuttu u codice di u servitore:
from flask import Flask, request
import webbrowser
import os
import re
app = Flask(__name__)
@app.route('/mycomp', methods=['POST'])
def hell():
json_string = request.json
if json_string['command'] == 'test':
return 'The server is running and waiting for commands...'
if json_string['command'] == 'openweb':
webbrowser.open(url='https://www.'+json_string['data'], new=0)
return 'Site opening ' + json_string['data'] + '...'
if json_string['command'] == 'shell':
os.system(json_string['data'])
return 'Command execution ' + json_string['data'] + '...'
if json_string['command'] == 'link':
links = open('links.txt', 'r')
for i in range(int(json_string['data'])):
link = links.readline()
os.system(link.split('>')[0])
return 'Launch ' + link.split('>')[1]
if __name__ == '__main__':
app.run(host='0.0.0.0')
Aghju digià scaricatu tuttu u codice, hè ora di spiegà l'essenza.
Tuttu u codice corre nantu à l'urdinatore lucale nantu à u portu 5000. Per interagisce cù u servitore, avemu da mandà una dumanda JSON POST.
Struttura di dumanda JSON:
{‘command’: ‘comecommand’, ‘data’: ‘somedata’}
Ebbè, hè sensu chì "cumandamentu" hè u cumandamentu chì vulemu eseguisce. E 'dati' sò l'argumenti di cumanda.
Pudete scrive è mandà richieste JSON per interagisce cù u servitore manualmente (e dumande vi aiutanu). O pudete scrive un cliente di cunsola.
Scrive un cliente
Code:
import requests
logo = ['nn',
'****** ********',
'******* *********',
'** ** ** **',
'** ** ** ** Written on Python',
'******* ** **',
'******** ** **',
'** ** ** ** Author: ROBOTD4',
'** ** ** **',
'** ** ** **',
'******** *********',
'******* ********',
'nn']
p = ''
iport = '192.168.1.2:5000'
host = 'http://' + iport + '/mycomp'
def test():
dict = {'command': 'test', 'data': 0}
r = requests.post(host, json=dict)
if r.status_code == 200:
print (r.content.decode('utf-8'))
def start():
for i in logo:
print(i)
start()
test()
while True:
command = input('>')
if command == '':
continue
a = command.split()
if command == 'test':
dict = {'command': 'test', 'data': 0}
r = requests.post(host, json=dict)
if r.status_code == 200:
print (r.content.decode('utf-8'))
if a[0] == 'shell':
for i in range(1, len(a)):
p = p + a[i] + ' '
dict = {'command': 'shell', 'data': p}
r = requests.post(host, json=dict)
if r.status_code == 200:
print (r.content.decode('utf-8'))
p = ''
if a[0] == 'link':
if len(a) > 1:
dict = {'command': 'link', 'data': int(a[1])}
r = requests.post(host, json=dict)
if r.status_code == 200:
print (r.content.decode('utf-8'))
else:
print('Комманда не содержит аргументов!')
if a[0] == 'openweb':
if len(a) > 1:
dict = {'command': 'openweb', 'data': a[1]}
r = requests.post(host, json=dict)
if r.status_code == 200:
print (r.content.decode('utf-8'))
else:
print('Комманда не содержит аргументов!')
if a[0] == 'set':
if a[1] == 'host':
ip = a[2] + ':5000'
if command == 'quit':
break
Spiegazioni:
Prima di tuttu, u modulu di richieste hè impurtatu (per interagisce cù u servitore). Quì sottu sò descrizzioni di e funzioni di partenza è di prova. E poi u ciculu in quale a magia passa. Avete lettu u codice? Allora capisce u significatu di a magia chì succede in u ciculu. Entre u cumandamentu - hè eseguitu. Shell - cumandamenti per a linea di cummanda (a logica hè fora di scala).
Test - verificate se u servitore hè in esecuzione (backdoor)
Link - usu di un "shortcut"
Openweb - apre un situ web
Quit - esce da u cliente
Set - stabilisce l'ip di u vostru urdinatore nantu à a reta lucale
È avà più nantu à u ligame.
Ci hè un schedariu link.txt accantu à u servitore. Cuntene ligami (percorsu sanu) à i schedari (video, photos, prugrammi).
A struttura hè cusì:
полный_путь>описание
полный_путь>описание
U risultatu
Avemu un servitore backdoor per cuntrullà un computer in una reta lucale (in una reta wi-fi). Tecnicamente, pudemu eseguisce u cliente da qualsiasi dispositivu chì hà un interprete python.
PS Aghju aghjustatu u cumandamentu set in modu chì se un urdinatore in a reta lucale hè assignatu un IP differente, pò esse cambiatu direttamente in u cliente.
Source: www.habr.com