-
Notifications
You must be signed in to change notification settings - Fork 3
/
get_binaries_from_gtfobins.py
63 lines (53 loc) · 1.81 KB
/
get_binaries_from_gtfobins.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
from git import Repo
import shutil
import os
import base64
temp_clone_dir = "git_temp"
gtfobins_repo = "https://github.com/GTFOBins/GTFOBins.github.io.git"
binary_folder = "_gtfobins"
gtfobins_base_url = "https://gtfobins.github.io/gtfobins/"
output_filename = "binaries"
output_file_content = ""
def list_files_in_directory(directory):
try:
# List all files in the directory
files = [f for f in os.listdir(directory) if os.path.isfile(os.path.join(directory, f))]
return files
except FileNotFoundError:
return f"The directory '{directory}' does not exist."
# rm old temp dir and create new one (if it still exists)
try:
shutil.rmtree(temp_clone_dir)
except:
pass
os.makedirs(temp_clone_dir, exist_ok=True)
# get gtfobins repository and extract binaries
print("[*] Cloning gtfobins repo to extract binary infos...")
Repo.clone_from(gtfobins_repo, temp_clone_dir)
binary_files = list_files_in_directory(temp_clone_dir + "/" + binary_folder)
# go through binaries, look for suid and extract technique
for binary in binary_files:
f = open(temp_clone_dir + "/" + binary_folder + "/" + binary, "r")
temp_binary_content = f.readlines()
f.close()
binary_payload = ""
store = 0
for line in temp_binary_content:
binary_payload += line
if "suid:" in line:
store = 1
if store == 1:
payload_write = str(base64.b64encode(binary_payload.encode()))
payload_write = payload_write[2:len(payload_write)-1]
output_file_content += binary.split(".")[0] + "," + gtfobins_base_url + binary.split(".")[0] + "," + payload_write + "\n"
# create binary file
f = open("binaries", "w")
f.write(output_file_content)
f.close()
# clean up
print("[*] Cleaning up...")
try:
shutil.rmtree(temp_clone_dir)
except:
pass
print("[+] Done.")