3.3 Webshell
Webshell也是一种后门,只不过这种后门不是命令行形式的,而是Web形式的,其原理是接收用户通过HTTP/HTTPS提交的命令,然后将命令执行结果返回给用户。
在Go语言中实现一个Web服务非常简单,可以直接使用标准库的net.http包来进行Web开发,以下代码的作用是启动一个Web服务:

想要实现一个简单的Webshell的功能,需要在handler中接收用户参数,然后利用exec/command包执行命令并返回命令的执行结果。
用户的Get请求可以用req.URL.Query().Get("cmd")来获取,命令执行的结果可以用http.ResponseWriter对象的Write方法返回。最终完成的代码如下所示:


将以上实现的程序进行编译,在服务器中启动后即为一个简单的Webshell,在浏览器中通过/?cmd=xxx来执行命令,如执行ls-al命令的结果如图3-4所示。

●图3-4 Go语言Webshell测试