View difference between Paste ID: 5BPi5FAL and
SHOW:
|
|
- or go back to the newest paste.
1 | - | |
1 | + | import java.net.*; |
2 | import java.io.*; | |
3 | ||
4 | public class LoginToMission { | |
5 | ||
6 | private static URL URLObj; | |
7 | private static URLConnection connect; | |
8 | private static String sessid = ""; | |
9 | ||
10 | public static void main() { | |
11 | try { | |
12 | URLObj = new URL("http://www.hackthissite.org/user/login"); | |
13 | connect = URLObj.openConnection(); | |
14 | connect.setDoOutput(true); | |
15 | connect.addRequestProperty("Referer", "http://www.hackthissite.org"); | |
16 | connect.addRequestProperty("User-agent", "User-Agent=Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13"); | |
17 | connect.addRequestProperty("Keep-Alive", "115"); | |
18 | connect.addRequestProperty("Connection", "keep-alive"); | |
19 | ||
20 | connect.connect(); | |
21 | } | |
22 | catch (MalformedURLException ex) { | |
23 | System.out.println("The URL specified was unable to be parsed or uses an invalid protocol. Please try again."); | |
24 | System.exit(1); | |
25 | } | |
26 | catch (Exception ex) { | |
27 | System.out.println("An exception occurred. " + ex.getMessage()); | |
28 | System.exit(1); | |
29 | } | |
30 | ||
31 | try { | |
32 | BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(connect.getOutputStream())); | |
33 | writer.write("username=BrandonHeat&password=**********&btn_submit=Login"); | |
34 | writer.close(); | |
35 | sessid = connect.getHeaderFields().toString(); | |
36 | sessid = sessid.substring(sessid.indexOf("Cookie=[") + 18, sessid.indexOf("; path=/]")); | |
37 | ||
38 | BufferedReader reader = new BufferedReader(new InputStreamReader(connect.getInputStream())); | |
39 | ||
40 | String lineRead = ""; | |
41 | ||
42 | while ((lineRead = reader.readLine()) != null) { | |
43 | System.out.println(lineRead); | |
44 | } | |
45 | ||
46 | reader.close(); | |
47 | } | |
48 | catch (Exception ex) { | |
49 | System.out.println("There was an error reading or writing to the URL: " + ex.getMessage()); | |
50 | } | |
51 | System.out.println(sessid); | |
52 | ||
53 | ||
54 | try { | |
55 | ||
56 | URLObj = new URL("http://www.hackthissite.org/missions/prog/2"); | |
57 | ||
58 | connect = URLObj.openConnection(); | |
59 | ||
60 | connect.addRequestProperty("Referer", "http://www.hackthissite.org/missions/programming"); | |
61 | connect.addRequestProperty("User-agent", "User-Agent=Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13"); | |
62 | connect.addRequestProperty("Keep-Alive", "115"); | |
63 | connect.addRequestProperty("Connection", "keep-alive"); | |
64 | connect.addRequestProperty("Cookie", "PHPSESSID="+sessid+";"); | |
65 | ||
66 | connect.connect(); | |
67 | ||
68 | String readline = ""; | |
69 | String temp = ""; | |
70 | ||
71 | BufferedReader reader = new BufferedReader(new InputStreamReader(connect.getInputStream())); | |
72 | ||
73 | while ((readline = reader.readLine())!=null) { | |
74 | temp += readline; | |
75 | } | |
76 | System.out.println(temp); | |
77 | } | |
78 | catch (Exception ex) { | |
79 | System.out.println("Exception thrown" + ex.getMessage()); | |
80 | } | |
81 | } | |
82 | ||
83 | public LoginToMission() { | |
84 | main(); | |
85 | } | |
86 | ||
87 | } |