-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcraft.py
More file actions
executable file
·142 lines (117 loc) · 4.14 KB
/
craft.py
File metadata and controls
executable file
·142 lines (117 loc) · 4.14 KB
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
# /// script
# requires-python = ">=3.10"
# dependencies = []
# ///
import os
import json
from hashlib import sha256
from base64 import b64encode
def read_file_return_base64ed_content(filename):
data = ""
with open(filename, 'r') as f:
data = f.read()
return b64encode(data.encode('utf-8')).decode('utf-8')
def filename_to_variable_name(filename):
basename = os.path.basename(filename)
return basename.replace(".", "_").upper()
def create_value_map(filepath:str):
variable_file_content_map = {}
files = os.listdir(filepath)
for file in files:
if file in [".command_history"]:
continue
curr_file = os.path.join(filepath, file)
if os.path.isfile(curr_file):
variable_file_content_map[curr_file] = read_file_return_base64ed_content(curr_file)
if os.path.isdir(curr_file):
variable_file_content_map.update(create_value_map(curr_file) )
return variable_file_content_map
def read_file(filename):
with open(filename) as f:
data = f.read()
return data
vscode_path = ".vscode"
foam_template = ".foam/templates"
template_head = """#!/bin/zsh
# __ __ __ ______ ____ _
# \ \ / /__ __ _ _ __ ___ _ _\ \ / / ___| / ___|___ __| | ___
# \ \ /\ / / _ \/ _` | '_ \ / _ \| '_ \ \ / /\___ \| | / _ \ / _` |/ _ \\
# \ V V / __/ (_| | |_) | (_) | | | \ V / ___) | |__| (_) | (_| | __/
# \_/\_/ \___|\__,_| .__/ \___/|_| |_|\_/ |____/ \____\___/ \__,_|\___|
# |_|
#
# Author: Esonhugh <weapon_vscode@eson.ninja>
# Path: createhackenv.sh
# Usage: createhackenv <foldername>
# Description: Create a hacking project with vscode based environment
weapon_vscode () {
echo "Creating VSCode Hack Environment"
echo "Usage: $0 <foldername>"
if [ -z "$1" ]
then
echo "No folder name given"
return 1
fi
mkdir -p $1/.vscode
mkdir -p $1/.foam/templates
"""
template_body = """
# __FILEPATH__
echo '__VALUE__' | base64 -d > $1/__FILEPATH__
"""
template_tail = """
echo "*" > $1/.vscode/.gitignore
echo "*" > $1/.foam/.gitignore
echo "!env.zsh" >> $1/.vscode/.gitignore
echo "!metasploit_handler.rc" >> $1/.vscode/.gitignore
echo "!msfconsole.rc" >> $1/.vscode/.gitignore
echo "!revshell.zsh" >> $1/.vscode/.gitignore
echo "Generate Success" "Launched VSCode"
code $1
}
# Create Alias for weapon_vscode
alias createhackenv=weapon_vscode
alias createhack=weapon_vscode
__LAUNCH_HELPER__
# Script Hash: __HASH__
"""
def generate_bash_script():
bash_script_content = ""
bash_script_content += template_head
for key, value in create_value_map(vscode_path).items():
bash_script_content += \
template_body. \
replace("__KEY__", filename_to_variable_name(key)). \
replace("__VALUE__", value). \
replace("__FILEPATH__", key)
for key, value in create_value_map(foam_template).items():
bash_script_content += \
template_body. \
replace("__KEY__", filename_to_variable_name(key)). \
replace("__VALUE__", value). \
replace("__FILEPATH__", key)
bash_script_content += template_tail. \
replace("__LAUNCH_HELPER__", read_file("launch_helper.zsh"))
return bash_script_content
def test():
content = read_file_return_base64ed_content("./vscode/source.zsh")
print(content)
dicts = create_value_map(vscode_path)
print(json.dumps(dicts, indent=4))
print(filename_to_variable_name("./vscode/source.zsh"))
print(filename_to_variable_name("./vscode/source.zsh"))
print(generate_bash_script())
def content_hash(content):
return sha256(content.encode('utf-8')).hexdigest()
def main():
print("reGenerating bash script")
content = generate_bash_script()
content = content.replace("__HASH__", content_hash(content))
print("Content: ")
print(content)
print("Writing to createhackenv.sh file")
with open("createhackenv.sh", 'w') as f:
f.write(content)
print("Done")
if __name__ == "__main__":
main()