-
Notifications
You must be signed in to change notification settings - Fork 3
/
merge-meterpreters.sh
executable file
·195 lines (175 loc) · 5.88 KB
/
merge-meterpreters.sh
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
#!/bin/bash
set -e
set -x
CWD=`pwd`
WD=/tmp/merge
DST=$WD/metasploit-payloads
PREHISTORY_C=$WD/prehistory_c
CURRENT_C=$WD/meterpreter_c
CURRENT_PHP=$WD/meterpreter_php
CURRENT_PYTHON=$WD/meterpreter_python
PREHISTORY_JAVA=$WD/prehistory_java
CURRENT_JAVA=$WD/meterpreter_java
CURRENT_GEM=$WD/metasploit-payloads-gem
SIGN=-S
(cd clean/metasploit-framework; git pull --rebase)
(cd clean/meterpreter; git pull --rebase)
(cd clean/metasploit-javapayload; git pull --rebase)
(cd clean/metasploit-payloads-gem; git pull --rebase)
rm -fr $WD
mkdir -p $WD
function filter_gem()
{
rm -fr $CURRENT_GEM
cp -a clean/metasploit-payloads-gem $CURRENT_GEM
(cd $CURRENT_GEM
git filter-branch -f --index-filter \
'git ls-files -s | gsed "s-\t\"*-&gem/-" |
GIT_INDEX_FILE="$GIT_INDEX_FILE.new" \
git update-index --index-info &&
mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE" || true' HEAD
git filter-branch -f --prune-empty --tree-filter 'rm -fr gem/meterpreter' HEAD
)
}
function filter_php()
{
rm -fr $CURRENT_PHP
cp -a clean/metasploit-framework $CURRENT_PHP
(cd $CURRENT_PHP
git filter-branch -f --prune-empty --subdirectory-filter data/meterpreter HEAD
git filter-branch -f --index-filter \
'git ls-files -s | gsed "s-\t\"*-&php/meterpreter/-" |
GIT_INDEX_FILE="$GIT_INDEX_FILE.new" \
git update-index --index-info &&
mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE" || true' HEAD
git filter-branch -f --prune-empty --tree-filter 'find . -type f -not -name '*.php' |xargs rm' HEAD
)
}
function filter_python()
{
rm -fr $CURRENT_PYTHON
cp -a clean/metasploit-framework $CURRENT_PYTHON
(cd $CURRENT_PYTHON
git filter-branch -f --prune-empty --subdirectory-filter data/meterpreter HEAD
git filter-branch -f --index-filter \
'git ls-files -s | gsed "s-\t\"*-&python/meterpreter/-" |
GIT_INDEX_FILE="$GIT_INDEX_FILE.new" \
git update-index --index-info &&
mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE" || true' HEAD
git filter-branch -f --prune-empty --tree-filter 'find . -type f -not -name '*.py' |xargs rm' HEAD
)
}
function filter_c()
{
rm -fr $PREHISTORY_C
cp -a clean/meterpreter-prehistory $PREHISTORY_C
(cd $PREHISTORY_C
git reset --hard HEAD^
git filter-branch -f --index-filter \
'git ls-files -s | gsed "s-\t\"*-&c/meterpreter/-" |
GIT_INDEX_FILE="$GIT_INDEX_FILE.new" \
git update-index --index-info &&
mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE" || true' HEAD
git filter-branch -f --prune-empty --tree-filter 'rm -fr meterpreter-c/java' HEAD
)
rm -fr $CURRENT_C
cp -a clean/meterpreter $CURRENT_C
(cd $CURRENT_C
git filter-branch -f --index-filter \
'git ls-files -s | gsed "s-\t\"*-&c/meterpreter/-" |
GIT_INDEX_FILE="$GIT_INDEX_FILE.new" \
git update-index --index-info &&
mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE" || true' HEAD
git fetch $PREHISTORY_C master:prehistory_c
echo `git log --pretty=oneline --reverse|head -1|cut -f 1 -d ' '` `git log --pretty=oneline prehistory_c |head -1|cut -f 1 -d ' '` > .git/info/grafts
git fast-export --signed-tags=warn --all > ../export
)
rm -fr $CURRENT_C
mkdir $CURRENT_C
(cd $CURRENT_C
git init
git fast-import < ../export
)
}
function filter_java()
{
rm -fr $PREHISTORY_JAVA
cp -a clean/meterpreter-prehistory $PREHISTORY_JAVA
(cd $PREHISTORY_JAVA
git reset --hard HEAD~2
git filter-branch -f --prune-empty --subdirectory-filter java HEAD
)
rm -fr $CURRENT_JAVA
cp -a clean/metasploit-javapayload $CURRENT_JAVA
(cd $CURRENT_JAVA
git filter-branch -f --index-filter \
'git ls-files -s | gsed "s-\t\"*-&java/-" |
GIT_INDEX_FILE="$GIT_INDEX_FILE.new" \
git update-index --index-info &&
mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE" || true' HEAD
git fetch $PREHISTORY_JAVA master:prehistory_java
echo 4ef3449e7cff6dc0d3c05cb65bc401697426ad04 9595ece04ecca4d6adf74fe3620c12115750415e > .git/info/grafts
git fast-export --signed-tags=warn --all > ../export
)
rm -fr $CURRENT_JAVA
mkdir $CURRENT_JAVA
(cd $CURRENT_JAVA
git init
git fast-import < ../export
)
}
function update_repo()
{
(
rm -fr $DST
mkdir -p $DST
git clone [email protected]:rapid7/metasploit-payloads.git $DST
filter_c
filter_java
cd $DST
git remote add -f current_c $CURRENT_C
git merge $SIGN -m "Merged c" current_c/master
git remote add -f current_java $CURRENT_JAVA
git merge $SIGN -m "Merged java" current_java/master
git push
)
}
function init_repo()
{
(
rm -fr $DST
mkdir -p $DST
git init $DST
cd $DST
filter_gem
git remote add -f current_gem $CURRENT_GEM
git merge $SIGN -m "Merged gem" current_gem/master
filter_c
git remote add -f current_c $CURRENT_C
git merge $SIGN -m "Merged c" current_c/master
filter_java
git remote add -f current_java $CURRENT_JAVA
git merge $SIGN -m "Merged java" current_java/master
filter_php
git remote add -f current_php $CURRENT_PHP
git merge $SIGN -m "Merged php" current_php/master
filter_python
git remote add -f current_python $CURRENT_PYTHON
git merge $SIGN -m "Merged python" current_python/master
git mv c/meterpreter/.gitmodules .
cp $CWD/gitmodules .gitmodules
sed -e "s/\.\.\\\pssdk/\.\.\\\.\.\\\.\.\\\pssdk/" -i "" \
c/meterpreter/make.bat c/meterpreter/workspace/ext_server_sniffer/ext_server_sniffer.vcxproj
git commit $SIGN . -m "Adjust submodule and pssdk paths"
patch -p1 < $CWD/0001-adjust-java-install-paths.patch
git commit $SIGN . -m "Adjust java install paths"
patch -p1 < $CWD/0002-adjust-posix-install-paths.patch
git commit $SIGN . -m "Adjust posix install paths"
cp $CWD/README.md $CWD/Makefile .
git add README.md Makefile
git commit $SIGN . -m "Add top-level README and Makefile"
git remote add github [email protected]:rapid7/metasploit-payloads.git
#git push -f github --mirror
)
}
update_repo