Skip to content

Commit

Permalink
make ask() -> ask_async() to prevent possibility of deadlock
Browse files Browse the repository at this point in the history
  • Loading branch information
rsmudge committed Mar 9, 2014
1 parent dd2168e commit 0c23fe9
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 38 deletions.
20 changes: 11 additions & 9 deletions scripts/browser.sl
Expand Up @@ -225,11 +225,12 @@ sub createFileBrowser {

$mkdir = [new JButton: "Make Directory"];
[$mkdir addActionListener: lambda({
local('$name');
$name = ask("Directory name:");
if ($name !is $null) {
ask_async("Directory name:", "", $this);
yield;

if ($1 !is $null) {
[$setcwd];
m_cmd($sid, "mkdir \" $+ $name $+ \"");
m_cmd($sid, "mkdir \" $+ $1 $+ \"");
m_cmd($sid, "ls");
}
# refresh?
Expand Down Expand Up @@ -377,18 +378,19 @@ sub buildFileBrowserMenu {
}, $file => $2, \$sid, \%types, \$setcwd, \$text));

item($1, "Execute", 'E', lambda({
local('$f $args');
local('$f');
[$setcwd];

$args = ask("Arguments?");
ask_async("Arguments?", "", $this);
yield;

foreach $f ($file) {
if ($args eq "") {
if ($1 eq "") {
m_cmd($sid, "execute -t -f \" $+ $f $+ \" -k");
}
else {
$args = strrep($args, '\\', '\\\\');
m_cmd($sid, "execute -t -f \" $+ $f $+ \" -k -a \" $+ $args $+ \"");
$1 = strrep($1, '\\', '\\\\');
m_cmd($sid, "execute -t -f \" $+ $f $+ \" -k -a \" $+ $1 $+ \"");
}
}
}, $file => $2, \$sid, \$setcwd));
Expand Down
9 changes: 7 additions & 2 deletions scripts/gui.sl
Expand Up @@ -111,6 +111,11 @@ sub ask {
return [JOptionPane showInputDialog: "$1", "$2"];
}

# safe version of ask...
sub ask_async {
[ui.SafeDialogs ask: "$1", "$2", $3];
}

# askYesNo("title", "text", &callback)
sub askYesNo {
[ui.SafeDialogs askYesNo: $1, $2, $3];
Expand Down Expand Up @@ -502,11 +507,11 @@ sub gotoFile {
[[Desktop getDesktop] open: $f];
}
catch $ex {
ask("Browse to this file:", $f);
ask_async("Browse to this file:", $f, {});
}
}
else {
ask("Browse to this file:", $f);
ask_async("Browse to this file:", $f, {});
}
}
catch $exception {
Expand Down
8 changes: 4 additions & 4 deletions scripts/hosts.sl
Expand Up @@ -56,10 +56,10 @@ sub host_items {
item($j, "Comprehensive", $null, createNmapFunction("--min-hostgroup 96 -sS -n -sU -T4 -A -v -PE -PP -PS80,443 -PA3389 -PU40125 -PY -g 53"));

item($1, "MSF Scans...", "M", {
local('$address');
$address = ask("Enter scan range (e.g., 192.168.1.0/24):", join(", ", [$targets getSelectedHosts]));
if ($address eq "") { return; }
launch_msf_scans($address);
ask_async("Enter scan range (e.g., 192.168.1.0/24):", join(", ", [$targets getSelectedHosts]), $this);
yield;
if ($1 eq "") { return; }
launch_msf_scans($1);
});

item($1, "DNS Enumerate", 'D', {
Expand Down
27 changes: 15 additions & 12 deletions scripts/menus.sl
Expand Up @@ -67,10 +67,12 @@ sub host_selected_items {
}

# ask for a label
$label = ask("Set label to:", $label);
if ($label !is $null) {
ask_async("Set label to:", $label, $this);
yield;

if ($1 !is $null) {
foreach $host ($hosts) {
%l[$host] = ["$label" trim];
%l[$host] = ["$1" trim];
}
call_async($mclient, "db.report_labels", %l);
}
Expand Down Expand Up @@ -182,14 +184,14 @@ sub armitage_items {
item($m, 'Reverse (wait for)', 'R', &listen_for_shellz);
separator($m);
item($m, 'Set LHOST...', 'L', {
local('$new');
$new = ask("What is the IP address of this system?", $MY_ADDRESS);
if ($new is $null) {
ask_async("What is the IP address of this system?", $MY_ADDRESS, $this);
yield;
if ($1 is $null) {
return;
}

# update the address in the right place.
$MY_ADDRESS = $new;
$MY_ADDRESS = $1;
[$cortana updateLocalHost: $MY_ADDRESS];
setg("LHOST", $MY_ADDRESS);

Expand Down Expand Up @@ -239,7 +241,7 @@ sub gotoURL {
[[Desktop getDesktop] browse: $url];
}
else {
ask("Browse to this URL:", $url);
ask_async("Browse to this URL:", $url, {});
}
}, $url => [[new URL: $1] toURI]);
}
Expand Down Expand Up @@ -309,10 +311,11 @@ sub init_menus {
[$frame bindKey: "Ctrl+O", { thread(&createPreferencesTab); }];
[$frame bindKey: "Ctrl+T", { [$frame snapActiveTab]; }];
[$frame bindKey: "Ctrl+L", {
local('$text');
$text = ask("What would you like to add to log?");
if ($text ne "") {
elog($text);
ask_async("What would you like to add to log?", "", $this);
yield;

if ($1) {
elog($1);
}
}];
[$frame bindKey: "Ctrl+Left", { [$frame previousTab]; }];
Expand Down
22 changes: 11 additions & 11 deletions scripts/util.sl
Expand Up @@ -253,15 +253,15 @@ sub cmd_safe {

sub createNmapFunction {
return lambda({
local('$address');
$address = ask("Enter scan range (e.g., 192.168.1.0/24):", join(" ", [$targets getSelectedHosts]));
if ($address eq "") { return; }
ask_async("Enter scan range (e.g., 192.168.1.0/24):", join(" ", [$targets getSelectedHosts]), $this);
yield;
if ($1 eq "") { return; }

local('$queue');
$queue = createDisplayTab("nmap");
elog("started a scan: nmap $args $address");
elog("started a scan: nmap $args $1");

[$queue addCommand: "x", "db_nmap $args $address"];
[$queue addCommand: "x", "db_nmap $args $1"];
[$queue addListener: {
showError("Scan Complete!\n\nUse Attacks->Find Attacks to suggest\napplicable exploits for your targets.");
}];
Expand All @@ -285,17 +285,17 @@ sub getBindAddress {
$address = split('\\s+', $address[0])[2];

if ($address eq "127.0.0.1") {
[SwingUtilities invokeLater: {
local('$address');
$address = ask("Could not determine attack computer IP\nWhat is it?");
if ($address ne "") {
$MY_ADDRESS = $address;
[lambda({
ask_async("Could not determine attack computer IP\nWhat is it?", "", $this);
yield;
if ($1 ne "") {
$MY_ADDRESS = $1;
thread({
setg("LHOST", $MY_ADDRESS);
setupHandlers();
});
}
}];
})];
}
else {
print_info("Used the tab method: $address");
Expand Down
9 changes: 9 additions & 0 deletions src/ui/SafeDialogs.java
Expand Up @@ -26,4 +26,13 @@ public void run() {
}
}).start();
}

public static void ask(final String text, final String initial, final SafeDialogCallback callback) {
new Thread(new Runnable() {
public void run() {
String result = JOptionPane.showInputDialog(text, initial);
callback.result(result);
}
}).start();
}
}

0 comments on commit 0c23fe9

Please sign in to comment.