Captcha Recognition using Generative Adversarial Network Implementation A Project Report of Capstone Project - 2 Submitted by PRINCE KUMAR (1613101516 / 16SCSE101103) in partial fulfillment for the award of the degree of Bachelor of Technology IN Computer Science and Engineering SCHOOL OF COMPUTING SCIENCE AND ENGINEERING Under the Supervision of Dr. Raza Abbas Haidri, M.Tech. Asst. APRIL / MAY- 2020
34
Embed
Captcha Recognition using Generative Adversarial Network ...
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Captcha Recognition using Generative
Adversarial Network Implementation
A Project Report of Capstone Project - 2
Submitted by
PRINCE KUMAR
(1613101516 /
16SCSE101103)
in partial fulfillment for the award of the degree
of
Bachelor of Technology
IN
Computer Science and Engineering
SCHOOL OF COMPUTING SCIENCE AND ENGINEERING
Under the Supervision of
Dr. Raza Abbas Haidri, M.Tech.
Asst.
APRIL / MAY- 2020
SCHOOL OF COMPUTING AND SCIENCE AND
ENGINEERING
BONAFIDE CERTIFICATE
Certified that this project report “CAPTCHA RECOGNITION USING
GENERATIVE ADVERSARIAL NETWORK IMPLEMENTATION” is
the bonafide work of “PRINCE KUMAR (1613101516)” who carried out the
project work under my supervision.
SIGNATURE OF HEAD
Dr. MUNISH SHABARWAL,
PhD (Management), PhD (CS)
Professor & Dean,
School of Computing Science &
Engineering
SIGNATURE OF SUPERVISOR
Dr. RAZA ABBAS HAIDRI,
M.Tech
Professor
School of Computing Science &
Engineering
1. Abstract
Captchas are widely implemented as stop gap measures in web services against
automated attack vectors like spamming and bruteforcing.In many scenarios
they are a single point of failure against such attack vectors till date despite
several methods having been demonstrated to break captchas and circumvent
the security that they offer by making use of advancement in image processing
and machine learning technology. In Spite of such efforts,they continue to be
widely deployed due to prior attacks being rigid in their approach and
extensively form fitted for a particular captcha type requiring intensive manual
effort to reconfigure to the ever changing captcha schemes and their associated
security mechanisms such as fuzzing and distortions and, requirement of large
training dataset that in absence of the captcha scheme source code becomes hard
to collect.The project aims to develop a generic captcha solver using the GAN
network approach to create a method where in minimal real captcha is required
to train the solver by augmenting the training and testing set with synthesized
captchas.This is achieved by first learning a captcha synthesizer to
automatically generate synthetic captchas to learn a base solver, and then fine-
tuning the base solver on a small set of real captchas using transfer learning.The
beauty of this method allows us to turn the workflow into a procedural one
allowing quick refitting to suit the needs of a different captcha than it was
previously trained on.The process also benefits from increased accuracy and
performance factors.
TABLE OF CONTENTS
Chapter No. TITLE Page No.
ABSTRACT (iii)
LIST OF FIGURES
LIST OF TABLES
(v)
(vii)
1 Introduction
1.1 Overall discription
1.2 Purpose
1.3 Motivation And Scope
1
1
2
3
2 Existing System
2.1 Model Based Approch
2.2 Deep Learning Based Approch
5
5
6
3 Proposed System 8
4 Implementation Details 13
5 Output/Results 23
6 Conclusion/Future Enhancement 26
7 References 27
LIST OF FIGURES
S NO. FIGURE TOPIC PAGE NO.
1. Sample Captcha Security Features 1
2. Model Based Approach 5
3. Degradation in Image due to Pre-
processing
6
4. Deep learning based Model using CNN 7
5. Generative Adversarial Network Model 8
6. Sample Captcha image Thresholding
and Resolution Reduction
9
7. Example of Captcha Pre-processing
Operation
10
8. Example Of CNN Model For Image
Recognition
11
9. Transfer Learning Process to Specialize
model to Particular use case
12
10. Fine tuning the fully connected end
layer
12
11. Security Features 15
12. Synthesized Model 16
13. Captcha Generator model 17
14. Unsegmented Characters 20
15. Character Segmentaion 20
16. Base Solver 22
17. Fine Tuning 22
18. Overall Process 22
19. Synthetic Captcha using Single Security
Mechanism
23
20. Synthetic Captcha w/o Security
features(Occluding lines,Background
Noise)
23
21. Synthetic Captcha with Security
Features(Occluding Lines/Background
Noise)
24
22. Example-1 Security Feature Removal by
Pix2Pix Pre-Processing(Occluding
Line,Background Noise)
24
23. Example-2 Security Feature Removal by
Pix2Pix Pre-Processing(Hollow
Character,Occluding Line)
24
24 Labelling of Recognized Captcha Letters 25
LIST OF TABLES
TABLE NO. TABLE TOPIC PAGE NO.
TABLE 1 Captchas And There
Accociated Properties
14
1. Introduction
1.1 | Overall Description
Text-based captcha(Completely Automated Public Turing Test to Tell Computers and Human
Apart) are extensively deployed as a major step in the security mechanism across the entire
web.Introduced in the year 1997 they were developed as a way to differentiate between
humans and bots so as to prevent automated security intrusion techniques.Early captchas
were simple text based images and proved sufficient in doing their tasks but with the advent
of modern machine learning algorithms various security features were introduced to make
them more robust as shown in below representation.
1.
Newer advancements in deep learning such as Convolutional Neural Networks
breakthroughs have presented methods to circumvent these security features but despite
the various attacks demonstrated against captchas they still continue to be deployed
extensively as the previous
attack were very rigid in their approach by either hard coding them for a specific captcha
scheme or requiring extensive human intervention and manual labour to gather data and
relabell it.The captcha scheme security features are rapidly changed and can easily outpace
the attack techniques before they become big enough to cause significant damage or at the
earliest sign of detection.Prior methods rely on image segmentation techniques and advanced
security mechanisms or any alteration in their processing breaks the prior solvers and
requires heavy expert involvement.These shortcoming of the previous attack techniques can
be circumvented by introducing Generative Adversarial Network for image translation tasks
in solvers that removes the need for massive labeled dataset of real captcha by augmenting
the training dataset with synthesized ones so as to increase the operational accuracy and
performance.The beauty of this process is that it is generic in its approach thus allowing
quick adaptation to new captcha scheme in a procedural fashion with minimal human effort
or may be automated altogether to adjust to a new captcha scheme by leveraging transfer
learning.
We achieve this by implementing a Generative Adversarial Network for generating synthetic
captchas that are a close match to the ones in question allowing us to rapidly train a base
solver on these synthetic dataset and then fine tuning the model utilising real captchas
effectively reducing the need for large data collection and labelling overhead which is quite
a challenge when the source code for the captcha schemes is unavailable.
1.2 | Purpose
The main aim/ goal of this project is to demonstrate the use of recently introduced
Generative Adversarial Network, a novel technique for image translation tasks to create a
generic text-based
captcha solver that can easily solve them with minimal demands on training data and
reliable performance as well as accuracy rate.The knowledge learned can also be
extrapolated for usage with different captcha schemes easily with minimal human
intervention.Through this project i hope to demonstrate the shortcomings of using captcha
techniques as security measures without proper consideration into the ease with which they
may be circumvented.These shortcomings may result in widespread spam and direct denial
of service attacks that may cause losses to the establishment.
1.3 | Motivation and Scope
The main motivation for this project came after trying to use websites wherein captchas had
been extensively employed as check stops against bots and as anti crawling mechanisms.The
captchas had been deployed repeatedly so as to prevent spamming from bot agents and
automated attack mechanisms but in actuality they hindered smooth user experience and
added an extra hoop that people had to jump through.Until there were not many reliable
methods to automatically circumvent the captchas in a reliable manner their use case may
have been justified but with the advent of modern machine learning techniques there is a
need to rethink their purpose as to what the captchas were trying to solve in the first place.As
a result I decided to create a project demonstrating a method to solve captchas automatically
in hopes that people would rethink the need and design of captchas to ensure they are
relevant in the current times instead of a hindrance in an otherwise smooth user experience.
The scope of this project is as follows:-
1. Text based Captchas
2. Single word captchas
3. Captchas with security mechanisms such as random lines and and fuzziness as
well as noise or text distortions
2. Existing Systems
Over the years there have been many demonstrations compromising the captcha system by
implementing OCR based solvers that implement standard character recognition but were
easily circumvented by adding confusion in the final output image.
With the advent of newer machine learning models there have been demonstrations
utilising deep learning based models for analysing captchas
Important demonstrations in this have been in the form of (a) Model Based Approach (b)
Deep Learning Based Approach
2.1 Model Based Approach-
The system works by employing a machine learning model utilising segmentation
technique to separate individual letters of the associated captcha and then use
simple character recognition models to deduce individual letters from the
segmented images.
2.
The technique heavily relies on segmentation process to ease the model
difficulty Segmentation tasks are usually accomplished by OpenCV blob or
pixel level manipulation functions and hence very form fitted to a particular
captcha scheme.
The preprocessing task is also very important for successful segmentation and can
easily be defeated by complex security features.An example of a complex security
feature which degrades the original captcha while undergoing pre-processing for
data extraction is as follows.
3.
Any alteration in the captcha scheme causes the solver to be reconfigured and
involves massive human intervention.
On the flipside this method is relatively robust and easy to use with good
accuracy against captchas with rudimentary security features.
a. Deep Learning Based Approach -
With the advent of powerful deep learning based algorithms there have been multiple
demonstrations utilising Convolutional Neural Network that have been used to
essentially create solvers that are more generic in nature and can be refactored to
changing needs.
4.
While this method offers a real generic solver for breaking captchas it suffers from a
major flaw as in the need for a huge dataset for training the convolutional neural
network that can be easily exploited in situations wherein the source code for the
captcha generating mechanism is unavailable.The two major methods for preventing
third party entity from collecting large dataset of captcha images from a webservice
that may be used for training neural network models are as follows-
i. Anti-Crawling Mechanisms
ii. Constantly Changing Security Mechanisms in captcha
Another service currently in the market are CAPTCHA solving services that hire human
labour in 3rd world countries like India,Bangladesh and Pakistan to solve the captcha and
upload the solution with per captcha solving rate of 20 paise per captcha but this system is
slow and in the current generation of Deep Learning a highly un-efficient method.
2. Proposed Model
The proposed model consists of four distinct segments each fulfilling a major step in the
overall system creating a modular system.
The four segments are as follows:-
1. Captcha Synthesis
Generate captchas that are visually similar to the target captchas. Generative
Adversarial Network-based captcha generator consists of two parts: a captcha
generator that tries to produce captchas which are as similar as possible to the target
captchas, and a discriminator that tries to identify the synthetic captchas from the real
ones.The process is continued till the discriminator fails to identify a certain major
portion of the generated captchas from the real ones.Later the generator (referred as
captcha synthesizer) is used to generate captchas as per demand with no upper
limit.The synthesizer can thus create unlimited number of labelled captchas visually
similar to the real ones without knowledge of the captcha schemes mode of operation.
5.
2. Preprocessing
Removal of captcha security features such as lines and letter rotations as well as
hollow fonts to create a systematically consistent data for ease of usage in further
steps.The pre-processing model consists of 2 major operation
1. OpenCV based thresholding operation to reduce the bit depth of input image data
and optimise resolution
6.
2. Removal of security features such as occluding lines rotations and
transformations to generate clean images for usage with the next layers.This utilises
a specialised GAN called Pix2Pix which is excellent for image translation tasks.The
Pix2Pix model is trained with the synthetic captchas generated by the synthesiser
and their corresponding
clean versions without security features.The trained model can now be used for
any unseen captcha image of the target scheme.
7.
3. Training the Base Solver
With the captcha synthesizer and the pre-processing model in place, generate a large
number of synthetic captchas together with their labels (i.e., corresponding characters) and
use this dataset to learn a base solver for a target captcha scheme.Captcha solver is a