Backdoors, Git, Github, Python

Github APIv3 python wrapper

pygithub3 is a Github APIv3 python wrapper.

Search in commits message

from pygithub3 import Github
 
gh = Github(token=access_token, user=username, repo=myrepo)
commits=[]
commits = gh.repos.commits.list().all()
for c in commits:
    if 'blahblah' == c.commit.message:
        pass

Search a file by name to download

from pygithub3 import Github
 
gh = Github(token=access_token, user=username, repo=myrepo)
tree = gh.git_data.trees.get('heads/master')
for t in tree.tree:
    if 'blahblah' == t['path']:
        blob = gh.git_data.blobs.get(t['sha'])
        filedata = base64.b64decode(blob.content)

Search a file by name to download

from pygithub3 import Github
 
def currentCommit(github):
    ref = github.git_data.references.get('heads/master')
    commit = github.git_data.commits.get(sha=ref.object['sha'])
    return ref.object['sha'], commit.tree['sha']
 
def createCommit(github, parent_sha, tree, message):
    mycommit = github.git_data.commits.create(
        data={
            'message': message,
            'parents': [parent_sha],
            'tree': tree.sha
        }
    )
    github.git_data.references.update(ref='heads/master', data={'sha': mycommit.sha})
    return mycommit
 
def createTree(github, basecommit, blobs):
    tree = []
    for blob in blobs:
        tree.append({
            'path': blob.path,
            'type': 'blob',
            'sha': blob.sha,
            'mode': "100644"
        })
    data = {
        'base_tree': basecommit,
        'tree': tree
    }
    tree = github.git_data.trees.create(data)
    return tree
 
def addBlob(github, path, content, encoding="utf-8"):
    blob = github.git_data.blobs.create(data={
        'content': content,
        "encoding": encoding
    })
    blob.path = path
    return blob
 
filename = 'blahblah'
comment = 'mycomment blah blah'
blobs = []
 
file = open(filename, 'rb').read()
filedata = base64.b64encode(file)
 
gh = Github(token=access_token, user=username, repo=myrepo)
parentSha, baseCommit = currentCommit(gh)
 
blobs.append(addBlob(gh, filename, str(filedata)))
tree = createTree(gh, baseCommit, blobs)
createCommit(gh, parentSha, tree, comment)