Login Register






Tutorial Send Command to Java Program filter_list
Author
Message
Send Command to Java Program #1
Lets say, for example, that we have 20 computers with our Java program running, and we want to send a command (or data) over the internet to all of them. That is what we will be learning about today.

DISCLAIMER: Security is outside of this tutorial's scope.


We will need a web server with simple PHP capabilities (you can find that for free just about anywhere). Our PHP script will get an input from a text box we fill out in our browser. It will then save that data into a file. Our Java app(s) will retrieve that file from the internet and extract our command. It's as simple as that.

This is the PHP script (index.php) that will be on our web server:
Code:
<?php if ($_POST["cmd"]) { if (!file_put_contents("cmd", $_POST["cmd"])) { echo "ERROR: Command not saved to file."; } } ?> <html> <body> <form action="index.php" method="post"> Command: <input type="text" name="cmd"><br> <input type="submit"> </form> </body> </html>

This is our Java code:
Code:
package bot; import java.net.*; import java.io.*; public class BOT { public static String HOST = "http://yourwebserver.com/cmd"; private static String readRemoteFile(String url) { URL u; BufferedReader in; String data = null; try { u = new URL(url); in = new BufferedReader( new InputStreamReader(u.openStream()) ); data = in.readLine(); } catch (MalformedURLException mue) { System.out.println("ERROR: MalformedURLException occured."); mue.printStackTrace(); System.exit(1); } catch (IOException ioe) { System.out.println("ERROR: IOException occured."); ioe.printStackTrace(); System.exit(1); } finally { return data; } } public static void main(String[] args) { String cmd = readRemoteFile(HOST); System.out.println(cmd); } }

Everything is pretty self-explanatory.


Enjoy. Smile

Reply

RE: Send Command to Java Program #2
thanks for the nice representation of how to have 0 security whatsoever
how to pwn all 20 of those computers - send post request with malicious command as the parameter value

Reply

RE: Send Command to Java Program #3
(01-03-2016, 07:56 AM)meow Wrote: thanks for the nice representation of how to have 0 security whatsoever
how to pwn all 20 of those computers - send post request with malicious command as the parameter value

Did he ever say it was secure? And really, it's Java, nobody bothers to learn how to do malicious shit with it.
It's often the outcasts, the iconoclasts ... those who have the least to lose because they
don't have much in the first place, who feel the new currents and ride them the farthest.

[+] 1 user Likes Inori's post
Reply

RE: Send Command to Java Program #4
(01-03-2016, 08:12 AM)Chitoge Wrote: Did he ever say it was secure?

No, does that automatically mean I'm not allowed to have input on the security of it?

Reply

RE: Send Command to Java Program #5
(01-03-2016, 07:56 AM)meow Wrote: thanks for the nice representation of how to have 0 security whatsoever
how to pwn all 20 of those computers - send post request with malicious command as the parameter value

You are right ... A PHP script that saves abritrary text (from anyone on the internet) into a fil e on the server ... Not a secure solution.

But, like @'Chitoge' hinted, security is not in the scope of this tutorial. This tutorial is not for those who like to copy n' paste and have it all done. I have put a disclaimer in the thread.

(01-03-2016, 08:12 AM)Chitoge Wrote: Did he ever say it was secure? And really, it's Java, nobody bothers to learn how to do malicious shit with it.
(01-03-2016, 08:18 AM)Lust Wrote: No, you have all the right to say it's insecure. @"Chitoge" also has the right to critisize you for it.

Thanks.
(This post was last modified: 01-03-2016, 03:20 PM by m0dem.)

Reply