laitimes

Face recognition for an introduction to Python penetration testing

author:AILX10
Face recognition for an introduction to Python penetration testing

Recently, I received a network security book "Python Black Hat" presented by the Electronic Industry Press, with a total of 24 experiments in the book, and today reproduces the 11th experiment (face recognition), my test environment is MBP computer + Conda development environment. This experiment is immediately followed by the previous traffic image restoration, and the traffic image restoration can be connected to the man-in-the-middle attack, so that you can sniff out what content the target is browsing, such as pornographic websites, so as to create a breakthrough for social engineering fraud and extortion~

Face recognition for an introduction to Python penetration testing

AILX10

Excellent answerer in cybersecurity

Master's in Cybersecurity

Go to consult

1. First go to the Internet to search for a few face pictures, I originally planned to put all the pictures of beautiful women, here to pay tribute to the industry bosses

@腹黑

@kn1f3

Face recognition for an introduction to Python penetration testing

2. Download the required XML configuration file

wget https://eclecti.cc/files/2008/03/haarcascade_frontalface_alt.xml           
Face recognition for an introduction to Python penetration testing

3. Run the script on MBP

Face recognition for an introduction to Python penetration testing

4. View the face result in the faces folder

Face recognition for an introduction to Python penetration testing
Face recognition for an introduction to Python penetration testing
Face recognition for an introduction to Python penetration testing

Reference Code:

# -*- coding: utf-8 -*-
# @Time    : 2022/6/13 7:36 PM
# @Author  : ailx10
# @File    : detector.py

import cv2
import os

ROOT = "/Users/ailx10/py3hack/chapter4/picture"
FACES = "/Users/ailx10/py3hack/chapter4/faces"
TRAIN = "/Users/ailx10/py3hack/chapter4/training"

def detect(srcdir=ROOT,tgtdir=FACES,train_dir=TRAIN):
    for fname in os.listdir(srcdir):
        if not fname.upper().endswith(".JPG"):
            continue
        fullname = os.path.join(srcdir,fname)
        newname = os.path.join(tgtdir,fname)
        img = cv2.imread(fullname)
        if img is None:
            continue
        gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
        training = os.path.join(train_dir,"haarcascade_frontalface_alt.xml")
        cascade = cv2.CascadeClassifier(training)
        rects = cascade.detectMultiScale(gray,1.3,5)
        try:
            if rects.any():
                print("Got a face")
                rects[:,2:] += rects[:,:2]
        except AttributeError:
            print(f"No face found in {fname}")
            continue

        for x1,y1,x2,y2 in rects:
            cv2.rectangle(img,(x1,y1),(x2,y2),(127,255,0),2)
        cv2.imwrite(newname,img)

if __name__ == "__main__":
    detect()           
Face recognition for an introduction to Python penetration testing

Posted on 2022-06-13 19:52

Read on