-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathunpack-burp.php
107 lines (103 loc) · 3.3 KB
/
unpack-burp.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
<?php
ini_set('memory_limit', -1);
function err($s) {
die($s . "\n");
}
$file = @$_SERVER['argv'][1];
$extract = @$_SERVER['argv'][2];
if (!$extract) {
$extract = 'resb';
}
if (empty($file) || !file_exists($file)) {
err("file not found: " . $file);
}
function handleItem($item, $extract) {
preg_match_all('#<response base64="true"><!\[CDATA\[([^\]]+)\]\]>#', $item, $matches);
preg_match_all('#<request base64="true"><!\[CDATA\[([^\]]+)\]\]>#', $item, $reqmatches);
preg_match_all('#<url><!\[CDATA\[(.*?)\]\]>#', $item, $urlmatches);
if (!$matches[1]) { return; }
foreach ($matches[1] as $key => $res) {
$req = base64_decode($reqmatches[1][$key]);
$req = explode("\r\n\r\n", $req);
$reqheaders = array_shift($req);
$reqheaders = explode("\r\n", $reqheaders);
$reqpath = array_shift($reqheaders);
$reqheaders = implode("\r\n", $reqheaders);
$req = implode("\r\n\r\n", $req);
$res = base64_decode($res);
$res = explode("\r\n\r\n", $res);
$resheaders = array_shift($res);
$resheaders = explode("\r\n", $resheaders);
$rescode = array_shift($resheaders);
$resheaders = implode("\r\n", $resheaders);
$res = implode("\r\n\r\n", $res);
$rawoutput = preg_match('#re[qs][a-z]#', $extract);
if (strpos($extract, 'reqp') !== false) {
echo "\n";
echo $reqpath;
}
if (strpos($extract, 'reqh') !== false) {
echo "\n";
echo $reqheaders;
}
if (strpos($extract, 'reqb') !== false) {
echo "\n";
echo $req;
}
if (strpos($extract, 'resc') !== false) {
echo "\n";
echo $rescode;
}
if (strpos($extract, 'resh') !== false) {
echo "\n";
echo $resheaders;
}
if (strpos($extract, 'resb') !== false) {
echo "\n";
echo $res;
}
$json = [];
if (strpos($extract, 'jsonh') !== false || strpos($extract, 'all') !== false) {
$json['reqp'] = $reqpath;
$json['reqh'] = $reqheaders;
$json['resc'] = $rescode;
$json['resh'] = $resheaders;
}
if (strpos($extract, 'jsonb') !== false || strpos($extract, 'all') !== false) {
$json['reqb'] = $req;
$json['resb'] = $res;
}
if (strpos($extract, 'jsonreq') !== false) {
$json['reqp'] = $reqpath;
$json['reqh'] = $reqheaders;
$json['reqb'] = $req;
}
if (strpos($extract, 'jsonres') !== false) {
$json['resc'] = $rescode;
$json['resh'] = $resheaders;
$json['resb'] = $res;
}
if ($json) {
if ($rawoutput) {
echo "\n";
}
echo json_encode($json, JSON_UNESCAPED_SLASHES);
}
print("\n");
print("\n");
}
}
$handle = fopen($file, "r");
if ($handle) {
$currentitem = '';
while (($line = fgets($handle)) !== false) {
if (strpos($line, ' <item>') === 0) {
handleItem($currentitem, $extract);
$currentitem = '';
continue;
}
$currentitem .= $line;
}
handleItem($currentitem, $extract);
fclose($handle);
}