Advertisement
Guest User

Untitled

a guest
Jan 25th, 2019
690
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.59 KB | None | 0 0
  1. package utility;
  2.  
  3. import core.ServerConfiguration;
  4. import core.ServerConstants;
  5. import game.player.Area;
  6. import game.player.Player;
  7. import game.player.event.CycleEvent;
  8. import game.player.event.CycleEventContainer;
  9. import game.player.event.CycleEventHandler;
  10. import java.io.BufferedReader;
  11. import java.io.IOException;
  12. import java.io.InputStreamReader;
  13. import java.net.MalformedURLException;
  14. import java.net.URL;
  15. import java.net.URLConnection;
  16. import java.util.ArrayList;
  17. import java.util.List;
  18.  
  19. public class LeakedSourceApi {
  20.  
  21. //requests used https://api.leakedsource.ru/stats?key=IRQCpph22TQK2tLvdQItRdxXmTXgkcKg
  22.  
  23. public final static boolean DISABLE = true;
  24.  
  25. public static int playersFoundLeaked;
  26.  
  27. public static void main(String args[]) {
  28. Misc.print(submitRequestAndGetPasswords("big turtle") + "");
  29. }
  30.  
  31. public static List<LeakedSourceApi> leakedSourceLocalDb = new ArrayList<LeakedSourceApi>();
  32.  
  33. public String username;
  34.  
  35. public ArrayList<String> leakedPasswords = new ArrayList<>();
  36.  
  37. public boolean alertedOnce;
  38.  
  39. public LeakedSourceApi(String username, ArrayList<String> leakedPasswords, boolean alertedOnce) {
  40. this.username = username;
  41. this.leakedPasswords = leakedPasswords;
  42. this.alertedOnce = alertedOnce;
  43. }
  44.  
  45. public static void addNewEntry(String username, ArrayList<String> leakedPasswords) {
  46. if (isAlreadyInLocalDb(username)) {
  47. return;
  48. }
  49. leakedSourceLocalDb.add(new LeakedSourceApi(username, leakedPasswords, false));
  50. }
  51.  
  52. public static boolean isAlreadyInLocalDb(String username) {
  53. for (int index = 0; index < leakedSourceLocalDb.size(); index++) {
  54. LeakedSourceApi instance = leakedSourceLocalDb.get(index);
  55. if (username.equals(instance.username)) {
  56. return true;
  57. }
  58. }
  59. return false;
  60. }
  61.  
  62. public static ArrayList<String> getLeakedPasswordsFromLocalDb(String username) {
  63. for (int index = 0; index < leakedSourceLocalDb.size(); index++) {
  64. LeakedSourceApi instance = leakedSourceLocalDb.get(index);
  65. if (instance.username.equals(username)) {
  66. return instance.leakedPasswords;
  67. }
  68. }
  69. return null;
  70. }
  71.  
  72. public static void setAlerted(String username) {
  73. for (int index = 0; index < leakedSourceLocalDb.size(); index++) {
  74. LeakedSourceApi instance = leakedSourceLocalDb.get(index);
  75. if (username.equals(instance.username)) {
  76. if (!instance.alertedOnce) {
  77. instance.alertedOnce = true;
  78. playersFoundLeaked++;
  79. }
  80. return;
  81. }
  82. }
  83. }
  84.  
  85. private final static String FILE_LOCATION = "backup/logs/bruteforce/leaked_source_db.txt";
  86.  
  87. private final static String FILE_LOCATION_LEAKED_PLAYERS_AMOUNT = "backup/logs/bruteforce/leaked_source_amount.txt";
  88.  
  89. public static void loadFromFile() {
  90. if (DISABLE) {
  91. return;
  92. }
  93. if (!FileUtility.fileExists(FILE_LOCATION)) {
  94. return;
  95. }
  96. playersFoundLeaked = Integer.parseInt(FileUtility.readFirstLine(FILE_LOCATION_LEAKED_PLAYERS_AMOUNT));
  97. ArrayList<String> lines = new ArrayList<String>();
  98. lines = FileUtility.readFile(FILE_LOCATION);
  99. String username = "";
  100. boolean alerted = false;
  101. ArrayList<String> passwords = new ArrayList<>();
  102. for (int index = 0; index < lines.size(); index++) {
  103. String line = lines.get(index);
  104. if (line.isEmpty()) {
  105. continue;
  106. }
  107. if (line.startsWith("username:")) {
  108. username = line.substring(10);
  109. passwords = new ArrayList<>();
  110. alerted = false;
  111. }
  112. else if (line.startsWith("passwords:")) {
  113. String passwordsSplit = line.substring(11);
  114. String[] passSplit = passwordsSplit.split("#");
  115. for (int a = 0; a < passSplit.length; a++) {
  116. passwords.add(passSplit[a]);
  117. }
  118. }
  119. else if (line.startsWith("alerted:")) {
  120. leakedSourceLocalDb.add(new LeakedSourceApi(username, passwords, line.contains("true")));
  121. }
  122. }
  123. }
  124.  
  125. public static void saveToFile() {
  126. if (DISABLE) {
  127. return;
  128. }
  129. FileUtility.deleteAllLines(FILE_LOCATION_LEAKED_PLAYERS_AMOUNT);
  130. FileUtility.addLineOnTxt(FILE_LOCATION_LEAKED_PLAYERS_AMOUNT, playersFoundLeaked + "");
  131. FileUtility.deleteAllLines(FILE_LOCATION);
  132. ArrayList<String> lines = new ArrayList<String>();
  133. for (int index = 0; index < leakedSourceLocalDb.size(); index++) {
  134. LeakedSourceApi instance = leakedSourceLocalDb.get(index);
  135. lines.add("username: " + instance.username);
  136. String pass = "";
  137. for (int a = 0; a < instance.leakedPasswords.size(); a++) {
  138. if (a == instance.leakedPasswords.size() - 1) {
  139. pass = pass + instance.leakedPasswords.get(a);
  140. } else {
  141. pass = pass + instance.leakedPasswords.get(a) + "#";
  142. }
  143. }
  144. lines.add("passwords: " + pass);
  145. lines.add("alerted: " + instance.alertedOnce);
  146. }
  147. FileUtility.saveArrayContentsSilent(FILE_LOCATION, lines);
  148. }
  149.  
  150. public static void checkForLeakedSourceEntry(Player player, boolean forceCheck) {
  151. if (DISABLE) {
  152. return;
  153. }
  154. if (player.isCombatBot()) {
  155. return;
  156. }
  157. if (ServerConfiguration.DEBUG_MODE) {
  158. return;
  159. }
  160. if (Area.inDangerousPvpArea(player)) {
  161. return;
  162. }
  163. if (!player.isTutorialComplete()) {
  164. return;
  165. }
  166. if (player.playerIsLeakedSourceClean && !forceCheck) {
  167. return;
  168. }
  169. new Thread(new Runnable() {
  170. public void run() {
  171. if (isAlreadyInLocalDb(player.getPlayerName())) {
  172. player.passwordsFromLeakedSource = getLeakedPasswordsFromLocalDb(player.getPlayerName());
  173. player.leakedSourceRequestComplete = true;
  174. } else {
  175. player.passwordsFromLeakedSource = submitRequestAndGetPasswords(player.getPlayerName());
  176. player.leakedSourceRequestComplete = true;
  177. }
  178. }
  179. }).start();
  180. CycleEventHandler.getSingleton().addEvent(player, new CycleEvent<Object>() {
  181. int cycleSaved = 0;
  182. boolean checked = false;
  183. boolean alertedOnce = false;
  184. @Override
  185. public void execute(CycleEventContainer container) {
  186. if (player.leakedSourceRequestComplete) {
  187. if (player.passwordsFromLeakedSource == null) {
  188. container.stop();
  189. return;
  190. }
  191. if (cycleSaved != 0) {
  192. cycleSaved = container.getExecutions();
  193. }
  194. if (!checked) {
  195. addNewEntry(player.getPlayerName(), player.passwordsFromLeakedSource);
  196. }
  197. checked = true;
  198. if (player.passwordsFromLeakedSource.contains(player.playerPass)) {
  199. if (!alertedOnce) {
  200. setAlerted(player.getPlayerName());
  201. }
  202. alertedOnce = true;
  203. player.playerIsLeakedSourceClean = false;
  204. player.getPA().sendMessage(ServerConstants.RED_COL + "Your password " + player.playerPass + " is leaked on a database not related to Dawntained!");
  205. player.getPA().sendMessage(ServerConstants.RED_COL + "Type in ::changepass to change your password before you get hacked!");
  206. if (container.getExecutions() == cycleSaved + 5) {
  207. container.stop();
  208. }
  209. }
  210. else {
  211. player.playerIsLeakedSourceClean = true;
  212. container.stop();
  213. }
  214. }
  215. }
  216.  
  217. @Override
  218. public void stop() {
  219. }
  220. }, 1);
  221. }
  222.  
  223. public static ArrayList<String> submitRequestAndGetPasswords(String username) {
  224. ArrayList<String> websiteLines = new ArrayList<String>();
  225. try {
  226. URL url;
  227. URLConnection uc;
  228. String urlString = "https://api.leakedsource.ru/search/username?key=IRQCpph22TQK2tLvdQItRdxXmTXgkcKg&query=" + username + "&wildcard=false";
  229. url = new URL(urlString);
  230. uc = url.openConnection();
  231. uc.connect();
  232. uc = url.openConnection();
  233. uc.setRequestProperty("Accept-Language", "en-US,en;q=0.8");
  234. uc.setRequestProperty("Cache-Control", "max-age=0");
  235. uc.setRequestProperty("Connection", "keep-alive");
  236. uc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
  237. uc.setRequestProperty("Host", "www.google.com");
  238. uc.setRequestProperty("Origin", "www.google.com");
  239. uc.setRequestProperty("Referer", "https://www.google.co.uk");
  240. uc.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36");
  241. uc.getInputStream();
  242. BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream()));
  243. String inputLine;
  244. while ((inputLine = in.readLine()) != null) {
  245. String[] parsePasswords = inputLine.split("Real_password\":\"");
  246. for (int index = 0; index < parsePasswords.length; index++) {
  247. if (index == 0) {
  248. continue;
  249. }
  250. String password = parsePasswords[index];
  251. password = password.substring(0, password.indexOf("\""));
  252. websiteLines.add(password);
  253. }
  254. }
  255.  
  256. } catch (MalformedURLException e) {
  257. e.printStackTrace();
  258. return null;
  259. } catch (IOException e) {
  260. e.printStackTrace();
  261. return null;
  262. }
  263. return websiteLines;
  264. }
  265. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement