python解决实际问题系列

最近偶然接触到了一个学习平台,Jerbrains Academy。pycharm和IDEA都是jetbrains旗下的产品。下面将以平台中一个Password Hacker项目作为例子,带你初步接触python。https://hyperskill.org/projects/80?track=2

这个项目是以一个进攻方和服务器管理员admin之间的攻防为背景展开的。所有参考代码在python3.9版本本地编译通过,工具是pycharm社区版

第一阶段的任务,相对简单,就是创建一个session,发送message并且关闭。

参考代码:

import socket
import sys
# - sys.argv[0] = file name
# - sys.argv[1] = hostname
# - sys.argv[2] = port
# - sys.argv[2] = message
# Create a new socket.
client_socket = socket.socket()
# Connect to a host and a port using the socket.
hostname=sys.argv[1]
port=int(sys.argv[2])
address=(hostname,port)
client_socket.connect(address)
# Send a message from the third command line argument to the host using the socket.

message=sys.argv[3]
message=message.encode()
client_socket.send(message)
# Receive the server’s response.
response=client_socket.recv(port)
response=response.decode()
# Print the server’s response.
print(response)
# Close the socket.
client_socket.close()

 

第二阶段的要求加入了简单的密码尝试

参考代码:

import socket
import sys
import string
import itertools

#input CMD
argumente = sys.argv
IP = argumente[1]
port = int(argumente[2])

#Connection to the server
client_socket = socket.socket()
client_socket.connect((IP, port))

#sending the flow of passwords
caractere = string.ascii_lowercase + string.digits

for i in range(1,4):
    brute_force = map(''.join, itertools.product(caractere, repeat=i))
    for j in brute_force:
        client_socket.send(j.encode())
        byte_response = client_socket.recv(1024)
        response = byte_response.decode()
        if response == 'Connection success!':
            print(j)
            break
        else:
            continue

client_socket.close()

 

第三阶段你需要对每个可能密码的大小写做尝试,参考代码:

 

import socket
import sys

import itertools



#input CMD
argumente = sys.argv
IP = argumente[1]
port = int(argumente[2])

#Connection to the server
client_socket 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值