Skip to content

Commit

Permalink
make askYesNo async to avoid deadlock.
Browse files Browse the repository at this point in the history
  • Loading branch information
rsmudge committed Mar 9, 2014
1 parent 107585f commit dd2168e
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 12 deletions.
2 changes: 1 addition & 1 deletion scripts/collaborate.sl
Expand Up @@ -46,7 +46,7 @@ sub verify_server {
return $null;
}

$check = askYesNo("The team server's fingerprint is:\n\n<html><body><b> $+ $1 $+ </b></body></html>\n\nDoes this match the fingerprint shown\nwhen the team server started?", "Verify Fingerprint");
$check = [javax.swing.JOptionPane showConfirmDialog: $null, "The team server's fingerprint is:\n\n<html><body><b> $+ $1 $+ </b></body></html>\n\nDoes this match the fingerprint shown\nwhen the team server started?", "Verify Fingerprint", [javax.swing.JOptionPane YES_NO_OPTION]];

if ($check) {
%rejected[$1] = 1;
Expand Down
4 changes: 2 additions & 2 deletions scripts/gui.sl
Expand Up @@ -111,9 +111,9 @@ sub ask {
return [JOptionPane showInputDialog: "$1", "$2"];
}

# askYesNo("title", "text")
# askYesNo("title", "text", &callback)
sub askYesNo {
return [JOptionPane showConfirmDialog: $null, $1, $2, [JOptionPane YES_NO_OPTION]];
[ui.SafeDialogs askYesNo: $1, $2, $3];
}

sub chooseFile {
Expand Down
4 changes: 2 additions & 2 deletions scripts/menus.sl
Expand Up @@ -223,11 +223,11 @@ sub main_attack_items {
});

item($1, "Hail Mary", 'H', {
if (!askYesNo("Once started, the Hail Mary will launch a flood\nexploits at hosts in the current workspace. There\nis nothing stealthy about this action. If clumsily\nlaunching hundreds of exploits is what you would\nlike to do, press Yes.", "Really?!?")) {
askYesNo("Once started, the Hail Mary will launch a flood\nexploits at hosts in the current workspace. There\nis nothing stealthy about this action. If clumsily\nlaunching hundreds of exploits is what you would\nlike to do, press Yes.", "Really?!?", {
thread({
smarter_autopwn("p", min_rank());
});
};
});
});

setupMenu($1, "attacks", @());
Expand Down
4 changes: 2 additions & 2 deletions scripts/targets.sl
Expand Up @@ -328,10 +328,10 @@ sub clearHostFunction {
}

sub clearDatabase {
if (!askYesNo("This action will clear the database. You will lose all information\ncollected up to this point. You will not be able to get it back.\nWould you like to clear the database?", "Clear Database")) {
askYesNo("This action will clear the database. You will lose all information\ncollected up to this point. You will not be able to get it back.\nWould you like to clear the database?", "Clear Database", {
elog("cleared the database");
call_async($mclient, "db.clear");
}
});
}

# called when a target is clicked on...
Expand Down
15 changes: 10 additions & 5 deletions scripts/util.sl
Expand Up @@ -383,9 +383,9 @@ sub startMetasploit {
$text = readb($msg, -1);
closef($msg);

if (!askYesNo($text, "Uh oh!")) {
askYesNo($text, "Uh oh!", {
[gotoURL("http://www.fastandeasyhacking.com/nomsfrpcd")];
}
});
return;
}
catch $ex {
Expand Down Expand Up @@ -473,11 +473,16 @@ sub connectDialog {
if (isWindows()) {
showError("You must connect to a team server hosted on Linux.\nConnecting to a Metasploit RPC server on Windows is\nnot supported.");
[$dialog setVisible: 1];
return;
}
else if (!askYesNo("A Metasploit RPC server is not running or\nnot accepting connections yet. Would you\nlike me to start Metasploit's RPC server\nfor you?", "Start Metasploit?")) {
startMetasploit($u, $s, $p);
else {
askYesNo("A Metasploit RPC server is not running or\nnot accepting connections yet. Would you\nlike me to start Metasploit's RPC server\nfor you?", "Start Metasploit?", lambda({
startMetasploit($u, $s, $p);

# this is the only path to connect to a local metasploit
connectToMetasploit($h, $p, $u, $s);
}, \$u, \$s, \$p, \$h));
}
return;
}
}

Expand Down
29 changes: 29 additions & 0 deletions src/ui/SafeDialogs.java
@@ -0,0 +1,29 @@
package ui;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
import java.util.*;

/* Spawn common dialogs in their own thread (so they don't block Sleep interpreter)
and report their results to a callback function */
public class SafeDialogs {
/* our callback interface... will always return a string I guess */
public interface SafeDialogCallback {
public void result(String r);
}

/* prompts the user with a yes/no question. Does not call callback unless the user presses
yes. askYesNo is always a confirm action anyways */
public static void askYesNo(final String text, final String title, final SafeDialogCallback callback) {
new Thread(new Runnable() {
public void run() {
int result = JOptionPane.showConfirmDialog(null, text, title, JOptionPane.YES_NO_OPTION);
if (result == JOptionPane.YES_OPTION || result == JOptionPane.OK_OPTION) {
callback.result("yes");
}
}
}).start();
}
}

0 comments on commit dd2168e

Please sign in to comment.