zoukankan      html  css  js  c++  java
  • python黑帽子

    1.TCP客户端

      #AF_INET 使用标准的IPv4地址或者主机名
      #SOCK_STREAM是一个客户端
    import socket
    
    target_host = 'www.google.com'
    
    target_port = 80
    
    client = socket.socket(socket.AF_INET,socket.SOCKET_STREAM)
    client.connect = ((target_host,target_port))
    
    client.send('GET / HTTP/1.1
    Host:google.com
    
    ')
    
    response = client.recv(4096)
    
    print response


    2,TCP服务器

      多线程TCP服务器

    import socket
    import threading
    
    bind_ip = '0.0.0.0'
    bind_port = 9999
    
    server = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    
    server.bind((bind_ip,bind_port))
    
    server.listen(5)
    
    print 'TOTO:%s:%d' % (bind_ip,bind_port)

    def handle_client(client_socket)
      request = client_socket,recv(1024)
      
      print 'Received: %s' % request
      client_socket.send('ACK')
      client_socket.close()

    while True:
      client,addr = server.accept()
      print 'Accept from: %s:%d'%(addr[0],addr[1])
      
      client_handler = threading.Thread(target=handle_client,args=(client,))
      client_handler.start()

    3.UTP客户端

    import socket
    
    target_host = '127.0.0.1'
    target_port = 80
    
    cliect = socket.socket(socket,AF_INET,socket.SOCK_DGRAM)
    
    client = sendto('AAVVCC',(target_host,target_port))
    
    data,addr = client.recvfrom(4096)
    
    print data

    5.取代netcat

    import sys
    import socket
    import getopt
    import thrading
    import subporcess
    
    #定义全局变量
    listen             = False
    commanf        = False
    upload           = False
    execute = "" 
    target = ""
    upload_destination = ""
    port = 0          
    
    def usage():
        print  'BHP Net Tool'
        print
        print  "Usage:bhpnet.py -t target_host -p port"
        print  "-l  --listen           - listen on [host]:[port] for incoming connections"    
        print  "-e  --execute=file_to_run  - execute the given file upon receiving a connection"
        print " -c --command        -initialize a commang shell"
        print "-u   --upload=destination       - upon receiving connection upload a file and write to [destination]"
        print
        print
  • 相关阅读:
    7、配置私有仓库
    springcloud服务调用 list集合解析错误处理方法
    Mybatis-Plus 条件构造器的使用
    Mybatis-Plus 自定义sql
    Navicat Premium 15 安装与激活
    使用阿里云短信验证
    vue+element 表单el-radio单选框回显不能被选中问题
    类似性别(0、1)判断的table列表数据渲染
    使用docker 简单部署 ElasticSearch 以及 ElasticSearch-Head
    docker 配置镜像加速
  • 原文地址:https://www.cnblogs.com/a-dong/p/10080255.html
Copyright © 2011-2022 走看看