Three ways to deal with encryption JS

Source: Internet
Author: User

Often encountered in the Web page after logging on the user entered the account number and password through JS encryption, resulting in the simulation of such a site blocked

Here's a little bit. Three ways to solve this problem now

1. Use Python to achieve equal encryption of JS.

2. Log in using selenium emulation.

3. Using Pyexecjs to execute JS file

Test Site: http://bbs.125.la/

The password is encrypted by the Web browser F12 found at login

Further analysis and lookup, found to be named Md5.js? The RFI file is encrypted

Try to use the first method, but found that the content of this file is more complex to convert the program through Python, so discard

Using the second method

#coding =utf-8
Import time
From selenium import Webdriver
Import Selenium.webdriver.support.ui as UI

Start_url = ' http://bbs.125.la/'
Driver = Webdriver. Chrome ()
Driver.maximize_window ()
Driver.implicitly_wait (10)
Driver.get (Start_url)
#通过id方式定位
driver.find_element_by_id (' Ls_username '). Send_keys (U "n***i")
driver.find_element_by_id (' Ls_password '). Send_keys (U "sn*******9")
Driver.find_element_by_class_name (' pn '). Click ()
Time.sleep (3)
Driver.quit ()

This method attempts to log on successfully and tries the third method

#-*-Coding:utf-8-*-
Import OS
Import re
Import Urlparse
Import requests
Import JSON
Import Traceback
From Scrapy.selector import Htmlxpathselector
From scrapy.http import Htmlresponse
Import Execjs

Import Sys
Reload (SYS)
Sys.setdefaultencoding ("Utf-8")

if __name__ = = ' __main__ ':
url = ' http://bbs.125.la/member.php?mod=logging&action=login&loginsubmit=yes&infloat=yes& Lssubmit=yes&inajax=1 '
headers={
' Accept ': ' text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 ',
' accept-encoding ': ' gzip, deflate ',
' Accept-language ': ' zh-cn,zh;q=0.8 ',
' Cache-control ': ' max-age=0 ',
' Connection ': ' Keep-alive ',
' Content-length ': ' 87 ',
' Content-type ': ' application/x-www-form-urlencoded ',
' Host ': ' bbs.125.la ',
' Origin ': ' http://bbs.125.la ',
' Referer ': ' http://bbs.125.la/',
' Upgrade-insecure-requests ': ' 1 ',
' User-agent ': ' mozilla/5.0 (Windows NT 10.0; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/49.0.2623.221 safari/537.36 SE 2.X METASR 1.0 '
}
Username = ' N***i '
Password = ' sn*******9 '
Md5_password = Execjs.compile (open (r "Md5.js"). Read (). Decode ("Utf-8")). Call (' hex_md5 ', password) #md5. js file has been copied to the local
print ' Md5_password: ', Md5_password
R = requests.post (url,headers=headers,data= ' username=%s&password=%s&quickforward=yes&handlekey=ls '% ( Username,md5_password))

Successful output of encrypted password

Three ways to deal with encryption JS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.