This Presentation was for my talk at Null on Steganography using Python. This only serves as a on screen ppt to the talk. In order to understand this in-detail please follow my page to find the code
My INSURER PTE LTD - Insurtech Innovation Award 2024
Stego.ppt
1. Click to edit Master title style
1
STEGANOGRAPHY IN
PYTHON
MIHIR SHAH
2. Click to edit Master title style
2
$whoami
MIHIR SHAH | SHAHENSHAH99 | SHAHENSAH
3. Click to edit Master title style
3
W h a t i f I t o l d y o u t h i s a d o r a b l e p u p p y w a s h i d i n g a s e c r e t m e s s a g e ?
I n t h i s t a l k , w e ’ l l f i n d o u t h o w t h i s d o g w a s c o n v i n c e d t o h i d e a
m e s s a g e f o r u s . . . a n d h o w t o l e a r n i t s s e c r e t s . A l o n g t h e w a y, w e ’ l l
l e a r n a l o t a b o u t h o w i m a g e s w o r k a n d j u s t e n o u g h m a t h t o m a k e
y o u r h i g h s c h o o l t e a c h e r s a y “ I t o l d y o u s o . ”
L e t ’s s t a r t w i t h t h e b a s i c s . Yo u m i g h t a l r e a d y k n o w s o m e o f t h i s ,
b u t s t i c k w i t h m e h e r e
4. Click to edit Master title style
4
What is Steganography?
Origin of the term: steganos: secret – graphy: writing
Basically Steganography is hiding data into
images, Audio/Video files or even a wireless
Capture!(.pcap)
5. Click to edit Master title style
5
What else?
Well, barding from the hiding part, the logic or the
algorithm used in steganography is also used for di gital
watermarking.
But Why to use digital watermark?
1. Primarily for identification
2. Embedding a unique piece of information within a
medium (typically an image) without noticeably altering the
medium
3. Almost impossible to remove without seriously degrading
an image
6. Click to edit Master title style
6
Steganography and Digital Watermarking
• Digital watermarking hides data in a file, and the act of hiding
data makes it a form or steganography
• The key difference is their goals...
• Steganography: hiding information
• Watermarking: extending the file with extra information
• Steganographic information must never be apparent to a viewer
unaware of its presence.
7. Click to edit Master title style
7
Computers are really just things that take bits:
01100010 01101100 01100001 01100011
01101011 01101000 01101001 01101100
01101100 01110011 01101001 01101110
01100110 01101111 01110011 01100101
01100011 00101110 01100011 01101111
01101101 00101111 01101100 01101100
And turn them into other bits:
01101010 01101111 01101000 01101110
00100000 01110010 01101111 01100011
01101011 01110011
8. Click to edit Master title style
8
Unfortunately, though, not very many people can read
binary, and so those bits have to be turned into
something that actual humans can understand (since,
for now at least, computers exist to serve humans).
This creates problems. Who says what patterns of bits
turn into what words and pictures on a screen?
Nobody, that’s who. Er, also kind of everybody. Or
maybe just some certain special people? Turns out,
it’s a huge mess.
Various people and groups, at various times, for
various reasons, have stuck a flag in the ground and
said “THIS is how you turn a bunch of bits into an
image of a cat!”
9. Click to edit Master title style
9
That means that this staggeringly lame 2x2 pixel image that I made just now:
Is actually this:
01000010 01001101 01000110 00000000 00000000 00000000 BMF...
00000000 00000000 00000000 00000000 00110110 00000000 ....6.
00000000 00000000 00101000 00000000 00000000 00000000 ..(...
00000010 00000000 00000000 00000000 00000010 00000000 ......
00000000 00000000 00000001 00000000 00011000 00000000 ......
00000000 00000000 00000000 00000000 00010000 00000000 ......
00000000 00000000 00000000 00000000 00000000 00000000 ......
00000000 00000000 00000000 00000000 00000000 00000000 ......
00000000 00000000 00000000 00000000 00000000 00000000 ......
11111111 00100110 00000000 00000000 00000000 00000000 .&....
00000000 00000000 00000000 00000000 11111111 00000000 ......
01111111 01011011 00000000 00000000 .[..
10. Click to edit Master title style
10
In images, the least significant bit in R, G, and B for each pixel does nearly
nothing, while the most significant bit can really ruin your day. For instance,
this is what happens when you take each of the 8 bits out of a black and white
bitmap one layer at a time and make an image out of each layer. Each image
represents one “significance level” of bits; the most significant bit is on the top
left, and the least significant on the bottom right.
11. Click to edit Master title style
1111
See how the most significant bit (top left) makes up most of the
image, while the least significant bit (bottom right) is basically just
random noise? I bet you could change all of those least significant
bits (or maybe even the last two) and nothing would look different
in the final image. . . perhaps you could change them in some sort
of pattern. . . like in a message, say.
12. Click to edit Master title style
1212
Just a thought.
Here’s what happens when we take that puppy and flip the least significant
bits
of every pixel (each of R, G, and B) to all be 1, then the last two bits to both
be one, then the last three, and so on:
14. Click to edit Master title style
14
DEMO – MAKE BITS OF MESSAGE AND FEED IT TO THE IMAGE
14
15. Click to edit Master title style
1515
You’re probably wondering. . . why are we repeating the message so
much? Nine times per bit seems excessive.
It turns out that we aren’t the only people who have noticed that the
least significant bits in an image are basically random. Someone has
beaten us to our own hiding place, and they’re using it for boring stuff.
The objective of compression, according to Wikipedia, is “to reduce
irrelevance
and redundancy of the image data in order to be able to store or transmit
data
in an efficient form.”
16. Click to edit Master title style
1616
But that “irrelevant and redundant data” is where we wanted to put our sneaky
message stuff, and compression destroys those bits. Drat. Turns out if there are
useless bits, such as the least significant bit of each pixel value, they’re perfect
for hiding things in because nobody cares about them, but also the first to get
thrown out by compression... because nobody cares about them.
So we fight back, by repeating ourselves a bunch so that even if some bits get
flipped by compression, our data still mostly makes it through. It’s not elegant,
but it works.
17. Click to edit Master title style
17
DEMO – RETRIEVE THE DATA FROM AN IMAGE
17
18. Click to edit Master title style
18
UH-OH ERRORS!!
We a r e c u r r e n t l y f a c i n g t wo m a j o r p r o b l e m s wi t h o u r c o d e r i g h t n o w:
1 . T h e p r o g r a m i s n o t v e r y e ff i c i e n t , l i k e 9 t i m e r u n n i n g a l o o p i s n o
p i e c e o f c a k e , m y c o n d o l e n c e s t o t h e p r o c e s s o r. T h i s wa s a n i m a g e
wi t h s m a l l d i m e n s i o n b u t t h e i m a g e s wh i c h a r e l a r g e r i n s i z e , wo u l d
b e t a k i n g h e l l l o t o f t i m e ( R I P i n t e l )
2 . We s t i l l c a n n o t e v a d e f e w o f t h e c o m p r e s s i o n t e c h n i q u e s , e v e n a f t e r
c h a n g i n g t h e l a s t 3 L S B s t h e i m a g e i s s t i l l r e s i l i e n t t o i n c l u d e o u r
m e s s a g e
S o t h e m i l l i o n d o l l a r q u e s t i o n i s h o w t o o v e r c o m e t h e a b o v e t wo
i s s u e s ?
19. Click to edit Master title style
19
LETS LEARN PARITY FIRST
E s s e n t i a l l y, a p a r i t y b i t a d d s a c h e c k t o a n y g i v e n b i n a r y s t r i n g t h a t t e l l s
u s w h e t h e r t h e n u m b e r o f 1 - b i t s i n t h e s t r i n g i s o d d . F o r i n s t a n c e : t h e
s t r i n g 0 0 0 h a s n o 1 - b i t s , s o i t s p a r i t y b i t w o u l d b e 0 ( l e a v i n g u s w i t h t h e
f i n a l s t r i n g 0 0 0 0 ) . I n c o n t r a s t , t h e s t r i n g 0 1 0 h a s a n o d d n u m b e r o f 1 - b i t s ,
s o i t s p a r i t y b i t i s 1 , l e a v i n g u s w i t h 0 1 0 1 . Yo u ’ l l n o t i c e t h a t t h i s m e a n s
e v e r y s t r i n g h a s a n e v e n n u m b e r o f o n e s i n i t o n c e t h e p a r i t y b i t i s a d d e d .
T h e p r o c e s s i s :
1 . C o m p u t e p a r i t y b i t s b a s e d o n y o u r m e s s a g e . I f i t h a s a n o d d n u m b e r o f 1
v a l u e s , t h e p a r i t y b i t i s 1 , o t h e r w i s e t h e p a r i t y b i t i s 0 .
2 . P u t t h o s e p a r i t y b i t s i n t o t h e m e s s a g e ; t h e y ’ r e f r e q u e n t l y o n t h e e n d ,
b u t i t d o e s n ’ t a c t u a l l y m a t t e r w h e r e t h e y a r e s o l o n g a s t h e r e c e i v e r k n o w s
w h e r e t o f i n d t h e m .
20. Click to edit Master title style
20
Why Should I know
what on earth Parity is?
if a bit gets flipped somewhere in the string,
we can tell something is wrong by checking
the parity bit (if the string 0101 from above
comes across as 1101 , we know that the
parity bit of 110 should be 0 - but it’s
1, so something must be wrong).
But how to know which bit was flipped?
21. Click to edit Master title style
21
Hamming Codes
Case 1:
22. Click to edit Master title style
22
One Level Up:
Case 2 -
22
23. Click to edit Master title style
23
I think this is going somewhere
Case 3 -
23
24. Click to edit Master title style
24
Hey, I know what to do!
Case 4 -
24
25. Click to edit Master title style
25
OK, Perhaps I don’t, NVM
25
26. Click to edit Master title style
26
Now This Blows my head -
26
27. Click to edit Master title style
27
Lets put this all together in a python code and get done,
Checkout my GitHub repo for image-steganography
because the code involves a lot of math, which is like
awesome but then this talk should come to an end, mind
you I have included comments at almost each and every line
of code to explain what’s happening so anyone
understanding how python works, should be good to go to
read and understand the code
https://github.com/shahenshah99/Image-steganography.git
27
28. Click to edit Master title style
28
Lets Talk about the CodeFest-2018
CTF including steganography
28