// Imports import java.net.Socket; import java.net.ServerSocket; import java.io.*; // Thread to respond to pings class PingPlatesFaggotNetwork extends Thread { private Socket listeningSocket = null; private DataOutputStream listeningOutbound = null; private DataInputStream listeningInbound = null; public PingPlatesFaggotNetwork(Socket _incomingFaggotSocket) { try { // Get socket handle listeningSocket = _incomingFaggotSocket; // Acquire the input and output streams for listening socket listeningOutbound = new DataOutputStream(listeningSocket.getOutputStream()); listeningInbound = new DataInputStream(listeningSocket.getInputStream()); String responseLine; while ((responseLine = listeningInbound.readLine()) != null) { // Display each line to the console System.out.println(responseLine); if (responseLine.indexOf("PING") > -1) break; } sendListenerData("PONG " + responseLine.substring(responseLine.indexOf(":"))); } catch (Exception ex) { System.out.println(ex.getMessage()); } } // Send the listening server data private void sendListenerData(String _message) { try { listeningOutbound.writeBytes(_message + "\n"); } catch (Exception ex) { System.out.println(ex.getMessage()); } } } //Thread to send messages class PlatesFaggotNetworkServerThreadToSendMessages extends Thread implements Runnable { private Socket listeningSocket = null; private DataOutputStream listeningOutbound = null; private DataInputStream listeningInbound = null; private DataOutputStream incomingOutbound = null; private DataInputStream incomingInbound = null; private String channel = null; private Socket incomingFaggotSocket = null; public PlatesFaggotNetworkServerThreadToSendMessages(Socket _incomingFaggotSocket, String _channel) { try { channel = _channel; incomingFaggotSocket = _incomingFaggotSocket; // Get socket handle listeningSocket = _incomingFaggotSocket; // Incoming socket delcaration Socket incomingSocket = null; // Acquire the input and output streams for listening socket listeningOutbound = new DataOutputStream(listeningSocket.getOutputStream()); listeningInbound = new DataInputStream(listeningSocket.getInputStream()); // Server sockets ServerSocket serverSocket = new ServerSocket(8080); while((incomingSocket = serverSocket.accept()) != null) { Thread multiThread = new Thread(new PlatesFaggotNetworkServerThreadToSendMessages(_channel, incomingSocket, listeningOutbound)); } } catch (Exception ex) { System.out.println(ex.getMessage()); } } public PlatesFaggotNetworkServerThreadToSendMessages(String _channel, Socket _incomingFaggotSocket, DataOutputStream _listeningOutbound) { channel = _channel; incomingFaggotSocket = _incomingFaggotSocket; try { // Acquire the input and output streams for incoming socket incomingOutbound = new DataOutputStream(incomingFaggotSocket.getOutputStream()); incomingInbound = new DataInputStream(incomingFaggotSocket.getInputStream()); listeningOutbound = _listeningOutbound; String responseLine; while ((responseLine = incomingInbound.readLine()) != null) { // Display each line to the console System.out.println(responseLine); if (responseLine.indexOf("SENDMSG") > -1) break; } // Send message sendMessage(responseLine.substring(7)); // Cleanup incomingFaggotSocket.close(); } catch (Exception ex) { System.out.println(ex.getMessage()); System.exit(1); } } // Send a message to the server from a particular port public void sendMessage(String _message) { try { sendListenerData("PRIVMSG " + channel + " " + _message); } catch (Exception ex) { System.out.println(ex.getMessage()); } } // Send the listening server data private void sendListenerData(String _message) { try { listeningOutbound.writeBytes(_message + "\n"); } catch (Exception ex) { System.out.println(ex.getMessage()); } } } // This program will open public class LulzBot { // Basic connection data private String listeningServer = null; private int listeningPort = 0; private String receivingServer = null; private int receivingPort = 0; // Sockets private Socket listeningSocket = null; private Socket receivingSocket = null; // Data streams private DataOutputStream listeningOutbound = null; private DataInputStream listeningInbound = null; private DataOutputStream receivingOutbound = null; private DataInputStream receivingInbound = null; // Fake user data private String fakeUserName = null; private String fakeRealName = null; private String fakeHostName = null; private String fakeChatName = null; private String fakeChannel = null; // Real user data private String realUserName = null; private String realRealName = null; private String realHostName = null; private String realChatName = null; private String realChannel = null; // Default constructor public LulzBot(String _listeningServer, int _listeningPort, String _receivingServer, int _receivingPort) { listeningServer = _listeningServer; listeningPort = _listeningPort; receivingServer = _receivingServer; receivingPort = _receivingPort; } // Go function! private void go() { try { // Make connection to IRC server receivingSocket = new Socket(receivingServer, receivingPort); listeningSocket = new Socket(listeningServer, listeningPort); // Acquire the input and output streams for listening socket listeningOutbound = new DataOutputStream(listeningSocket.getOutputStream()); listeningInbound = new DataInputStream(listeningSocket.getInputStream()); // Acquire the input and output streams for receiving socket receivingOutbound = new DataOutputStream(receivingSocket.getOutputStream()); receivingInbound = new DataInputStream(receivingSocket.getInputStream()); // Read the server response String responseLine; while ((responseLine = listeningInbound.readLine()) != null) { // Display each line to the console System.out.println(responseLine); if (responseLine.indexOf("No ident response") > -1) break; } // Send listener user information sendListenerData("NICK " + fakeUserName); while ((responseLine = listeningInbound.readLine()) != null) { // Display each line to the console System.out.println(responseLine); if (responseLine.indexOf("PING") > -1) break; } sendListenerData("PONG " + responseLine.substring(responseLine.indexOf(":"))); sendListenerData("USER " + fakeUserName + " " + fakeHostName + " " + fakeChatName + " " + fakeRealName); sendListenerData("JOIN " + fakeChannel); while ((responseLine = receivingInbound.readLine()) != null) { // Display each line to the console System.out.println(responseLine); if (responseLine.indexOf("Found your hostname") > -1) break; } // Send receiver user information sendReceiverData("USER " + realUserName + " " + realHostName + " " + realChatName + " " + realRealName); sendReceiverData("NICK " + realUserName); sendReceiverData("JOIN " + realChannel); // Run thread to monitor pings PingPlatesFaggotNetwork ppfn = new PingPlatesFaggotNetwork(listeningSocket); ppfn.run(); // Run thread to monitor send traffic PlatesFaggotNetworkServerThreadToSendMessages pfnsttsm = new PlatesFaggotNetworkServerThreadToSendMessages(listeningSocket, fakeChannel); pfnsttsm.run(); // Get all messages while ((responseLine = listeningInbound.readLine()) != null) { // Display each line to the console if (responseLine.indexOf("PRIVMSG") > -1) { // Set nick boundaries int nickBegin = responseLine.indexOf(":"); int nickEnd = responseLine.indexOf("!"); // Set message boundaries int msgBegin = responseLine.indexOf(":", nickEnd); int msgEnd = responseLine.length(); // Extract actual values String nick = responseLine.substring(nickBegin+1, nickEnd); String msg = responseLine.substring(msgBegin+1, msgEnd); // Display message String outMessage = "<" + nick + ">\t" + msg; sendReceiverData("PRIVMSG " + realChannel + " " + outMessage); } } // Clean up listeningOutbound.close(); listeningInbound.close(); listeningSocket.close(); receivingOutbound.close(); receivingInbound.close(); receivingSocket.close(); } catch (Exception ex) { System.out.println(ex.getMessage()); } } // Send the listening server data private void sendListenerData(String _message) { try { listeningOutbound.writeBytes(_message + "\n"); } catch (Exception ex) { System.out.println(ex.getMessage()); } } // Send the receiving server data private void sendReceiverData(String _message) { try { receivingOutbound.writeBytes(_message + "\n"); } catch (Exception ex) { System.out.println(ex.getMessage()); } } // Set fake user data private void setFakeUserInfo(String _nick, String _host, String _chat, String _realName, String _channel) { fakeUserName = _nick; fakeRealName = _realName; fakeHostName = _host; fakeChatName = _chat; fakeChannel = _channel; } // Set real user data private void setRealUserInfo(String _nick, String _host, String _chat, String _realName, String _channel) { realUserName = _nick; realRealName = _realName; realHostName = _host; realChatName = _chat; realChannel = _channel; } // Instantiate the program public static void main(String[] args) { // Fake IRC Real IRC LulzBot lulz = new LulzBot("irc.ritirc.com", 6667, "irc.hobolooter.com", 6667); lulz.setFakeUserInfo("hobolooter|mobile", "hobo", "Chat", "Goober Mc. Noobster", "#chat"); lulz.setRealUserInfo("LulzBot3", "Lulz", "LulzChat", "Mr. Purdue", "#olderchat"); lulz.go(); } }