From 45e1b5a76f9ea154873449cad9bd45c2c7259de8 Mon Sep 17 00:00:00 2001 From: "matt123337@hotmail.com" Date: Fri, 27 Feb 2015 11:43:34 -0500 Subject: [PATCH] Added authentication to proxies, made a fix of sora for linux users and the transparantcy issue. --- .../core/network/proxy/ProxySocket.java | 37 +++++++- .../src/org/parabot/core/ui/BotDialog.java | 33 ++++--- .../src/org/parabot/core/ui/NetworkUI.java | 85 ++++++++++++++++--- 3 files changed, 129 insertions(+), 26 deletions(-) diff --git a/parabotv2/src/org/parabot/core/network/proxy/ProxySocket.java b/parabotv2/src/org/parabot/core/network/proxy/ProxySocket.java index d5629ca..d4ad9e2 100644 --- a/parabotv2/src/org/parabot/core/network/proxy/ProxySocket.java +++ b/parabotv2/src/org/parabot/core/network/proxy/ProxySocket.java @@ -31,6 +31,10 @@ public class ProxySocket extends Socket { private InetAddress addr; private int port; + private static String username = null, password = null; + + public static boolean auth = false; + private static InetAddress proxyInetAddress = null; private InetSocketAddress cachedAddr; @@ -183,14 +187,32 @@ public class ProxySocket extends Socket { DataOutputStream out = new DataOutputStream(getOutputStream()); DataInputStream in = new DataInputStream(getInputStream()); out.write(0x05); // the version - out.write(1); // number of authentication methods (no auth for now) + out.write(auth ? 2 : 1); // number of authentication methods (no auth + // for now) out.write(0); // the authentication (none) + if (auth) { + out.write(2); + } out.flush(); - if (in.read() != 0x05) // remote proxy version throw new IOException("Proxy server is not supported!"); - if (in.read() != 0x00) // make sure shit is a vaild request + switch (in.read()) { // auth method + case 0: + break; // no auth + case 2: + // username and pass stuff + out.write(0x01); // user/pass version # + out.write(username.length()); + out.write(username.getBytes()); + out.write(password.length()); + out.write(password.getBytes()); + out.flush(); + in.read(); // skip the version + if (in.read() == 0) // Successful login, continue + break; + default: throw new IOException("Proxy server declined request!"); + } // now to write the actual request out.write(0x05); // again the socks version @@ -270,5 +292,14 @@ public class ProxySocket extends Socket { public static int getConnectionCount() { return connections.size(); } + + public static void setLogin(String user, char[] pass) { + setLogin(user,new String(pass)); + } + + public static void setLogin(String user, String pass) { + username = user; + password = pass; + } } \ No newline at end of file diff --git a/parabotv2/src/org/parabot/core/ui/BotDialog.java b/parabotv2/src/org/parabot/core/ui/BotDialog.java index f9ab153..15634bf 100644 --- a/parabotv2/src/org/parabot/core/ui/BotDialog.java +++ b/parabotv2/src/org/parabot/core/ui/BotDialog.java @@ -1,11 +1,13 @@ package org.parabot.core.ui; +import java.awt.Color; +import java.awt.Dimension; + +import javax.swing.JDialog; + import org.parabot.core.ui.components.PaintComponent; import org.parabot.environment.OperatingSystem; -import javax.swing.*; -import java.awt.*; - /** * * @author Everel @@ -21,19 +23,29 @@ public class BotDialog extends JDialog { botUI.setDialog(this); setUndecorated(true); getRootPane().setOpaque(false); - if (!OperatingSystem.getOS().equals(OperatingSystem.OTHER)) { - setBackground(new Color(0, 0, 0, 0)); - } + if (!OperatingSystem.getOS().equals(OperatingSystem.OTHER)) { + try { + setBackground(new Color(0, 0, 0, 0)); + } catch (UnsupportedOperationException e) { + //My "fix" for the perpixel errors some user have when using VPSes + if (e.getMessage().contains("PERPIXEL_TRANS")) { + System.err + .println("WARNING: We were unable to set a translucent background!" + + "\n\tThis generally occurs with old/outdated graphics drivers. Please consider updating them if possible." + + "\n\tParabot will still attempt to run, however some GUI elements may or may not function."); + } + } + } setFocusableWindowState(true); setPreferredSize(botUI.getSize()); setSize(botUI.getSize()); setVisible(true); setContentPane(PaintComponent.getInstance(botUI.getSize())); botUI.setVisible(true); - + } - public void setDimensions(Dimension dimension) { + public void setDimensions(Dimension dimension) { setUndecorated(true); getRootPane().setOpaque(false); setBackground(new Color(0, 0, 0, 0)); @@ -44,14 +56,13 @@ public class BotDialog extends JDialog { setContentPane(PaintComponent.getInstance()); PaintComponent.getInstance().setDimensions(dimension); } - + public static BotDialog getInstance(BotUI botUI) { return instance == null ? instance = new BotDialog(botUI) : instance; } - + public static BotDialog getInstance() { return getInstance(null); } } - diff --git a/parabotv2/src/org/parabot/core/ui/NetworkUI.java b/parabotv2/src/org/parabot/core/ui/NetworkUI.java index 92e10cf..dcce19c 100644 --- a/parabotv2/src/org/parabot/core/ui/NetworkUI.java +++ b/parabotv2/src/org/parabot/core/ui/NetworkUI.java @@ -1,11 +1,24 @@ package org.parabot.core.ui; -import org.parabot.core.network.NetworkInterface; -import org.parabot.core.network.proxy.ProxySocket; -import org.parabot.core.network.proxy.ProxyType; -import org.parabot.core.ui.utils.UILog; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.net.SocketException; -import javax.swing.*; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JComboBox; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JPasswordField; +import javax.swing.JScrollPane; +import javax.swing.JTextField; +import javax.swing.ListSelectionModel; import javax.swing.border.EmptyBorder; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; @@ -13,11 +26,11 @@ import javax.swing.text.AttributeSet; import javax.swing.text.BadLocationException; import javax.swing.text.Document; import javax.swing.text.PlainDocument; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.KeyEvent; -import java.awt.event.KeyListener; -import java.net.SocketException; + +import org.parabot.core.network.NetworkInterface; +import org.parabot.core.network.proxy.ProxySocket; +import org.parabot.core.network.proxy.ProxyType; +import org.parabot.core.ui.utils.UILog; public class NetworkUI extends JFrame implements KeyListener, ActionListener, DocumentListener { @@ -31,8 +44,12 @@ public class NetworkUI extends JFrame implements KeyListener, ActionListener, private IntTextField proxyPort; private JButton submitButton; - JList[] macList; - JScrollPane[] macScrollList; + private JList[] macList; + private JScrollPane[] macScrollList; + + private JCheckBox authCheckBox; + private JTextField authUsername; + private JPasswordField authPassword; private NetworkUI() { initGUI(); @@ -58,6 +75,8 @@ public class NetworkUI extends JFrame implements KeyListener, ActionListener, proxyType = new JComboBox(ProxyType.values()); proxyType.setSelectedItem(ProxySocket.getProxyType()); + proxyType.addActionListener(this); + proxyHost = new JTextField(); proxyHost.addKeyListener(this); @@ -84,6 +103,15 @@ public class NetworkUI extends JFrame implements KeyListener, ActionListener, macList[i].ensureIndexIsVisible(value > 0 ? value - 1 : value); } + + authCheckBox = new JCheckBox("Auth"); + authCheckBox.addActionListener(this); + + authUsername = new JTextField(); + authUsername.setEnabled(false); + authPassword = new JPasswordField(); + authPassword.setEnabled(false); + JPanel p = createPanelUI(); add(p); setResizable(false); @@ -109,6 +137,19 @@ public class NetworkUI extends JFrame implements KeyListener, ActionListener, port.add(new JLabel("Proxy Port: ")); port.add(proxyPort); + Box auth = Box.createHorizontalBox(); + auth.add(authCheckBox); + + auth.add(Box.createHorizontalStrut(3)); + + auth.add(new JLabel("User:")); + auth.add(authUsername); + + auth.add(Box.createHorizontalStrut(3)); + + auth.add(new JLabel("Pass:")); + auth.add(authPassword); + Box macBox = Box.createHorizontalBox(); macBox.add(new JLabel("MAC:")); for (int i = 0; i < macList.length; i++) { @@ -127,6 +168,9 @@ public class NetworkUI extends JFrame implements KeyListener, ActionListener, main.add(Box.createVerticalStrut(5)); main.add(port); + main.add(Box.createVerticalStrut(5)); + main.add(auth); + main.add(Box.createVerticalStrut(5)); main.add(macBox); @@ -179,6 +223,23 @@ public class NetworkUI extends JFrame implements KeyListener, ActionListener, @Override public void actionPerformed(ActionEvent arg0) { + boolean b = false; + + if (arg0.getSource() == proxyType) { + authCheckBox.setEnabled(proxyType.getSelectedItem() == ProxyType.SOCKS5); + b = true; + } + + if (b || arg0.getSource() == authCheckBox) { + b = authCheckBox.isSelected() && authCheckBox.isEnabled(); + ProxySocket.auth = b; + authUsername.setEnabled(b); + authPassword.setEnabled(b); + return; + } + + ProxySocket.setLogin(authUsername.getText(), authPassword.getPassword()); + byte[] mac = new byte[macList.length]; for (int i = 0; i < mac.length; i++) mac[i] = (byte) Short.parseShort(