- Messaggi: 207
- Ringraziamenti ricevuti 0
Steganografia
- Valentina Bragaglia
-
Autore della discussione
- Offline
- Elite Member
-
Riduci
Di più
18 Anni 11 Mesi fa #35238
da Valentina Bragaglia
Steganografia è stato creato da Valentina Bragaglia
Volevo proporvi un programma che ho scritto qualche tempo fa nei ritagli di tempo, giusto per impegnare la mente nei momenti di noia (bei tempi...).
E' un programma di steganografia, tramite il quale si inseriscono dei messaggi all'interno di immagini, senza che queste appaiano modificate in alcun modo.
Per capire il funzionamento basta vedere il pezzo di codice sotto //heart.
Considerate che sono un elettronico, quindi il mio codice puo' sembrare zozzo ai puristi
Il programma funziona con jpeg che impacchettano l'info ad 8 bit, quindi se non funziona con una immagine...provate con un'altra (magari vecchiotta gh), tanto internet e' piena di immagini da poter usare
Esempio di utilizzo:
$ ./shadow-ass -h
Usage: ./shadow-ass [option] <file> {image}
Options are:
-c : code a message => file is a textfile, image is the image where will be inserted the message
-d : decode a message => file is an image
-h : print this help
Example:
coding a message: ./shadow-ass -c message.txt image
decoding a message: ./shadow-ass -d image
TheAlchemist
Metto il testo da iniettare nell'immagine in prova.txt ed effettuo la codifica:
$ ./shadow-ass -c prova.txt im-orig.jpg
Image lenght: 266876
Message lenght: 79
Image im-orig.jpg opened in read mode
Message 2code: Questo e' un fottuto messaggio di prova da inserire nell'immagine allora snado
I'm coding:.................................................................................................................................
.............................................................................................................................................
.............................................................................................................................................
.............................................................................................................................................
................................................................................Coded!
TheAlchemist
Il programma crea un clone dell'immagine im-orig.jpg, della stessa dimensione e con il prefisso "coded-"
$ ls -l
totale 932
-rw-r--r-- 1 x x 266876 2005-07-20 19:23 coded-im-orig.jpg
-rw-r--r-- 1 x x 266876 2005-07-19 14:11 im0000853xr.jpg
-rw-r--r-- 1 x x 266876 2005-07-19 13:47 im-orig.jpg
-rw-r--r-- 1 x x 79 2005-07-20 16:24 prova.txt
-rwxr-xr-x 1 x x 15599 2005-07-20 12:34 sa
-rwxr-xr-x 1 x x 15900 2005-07-20 16:33 sa2
-rw-r--r-- 1 x x 4970 2005-07-20 16:32 sa2.c
-rwxr-xr-x 1 x x 15911 2005-07-20 16:11 shadow-ass
-rw-r--r-- 1 x x 4571 2005-07-20 12:52 shadow-ass_0.5.c
-rw-r--r-- 1 x x 4942 2005-07-20 15:34 shadow-ass_0.6.c
-rw-r--r-- 1 x x 4673 2005-07-20 15:47 shadow-ass_1.0.c
-rw-r--r-- 1 x x 4968 2005-07-20 16:11 shadow-ass_1.1.c
-rwxr-xr-x 1 x x 15911 2005-07-20 16:33 shadow-ass_1.2
-rw-r--r-- 1 x x 4970 2005-07-20 16:33 shadow-ass_1.2.c
-rwxr-xr-x 1 x x 3997 2005-07-19 22:54 shadow-ass.c
-rwxr-xr-x 1 x x 3255 2005-07-19 20:20 shadow-ass.c.orig
-rw-r--r-- 1 x x 92 2005-07-20 15:55 voting_bar.gif
Potete vedere la straordinaria somiglianza tra le due foto, l'aver inserito il messaggio non si nota affatto!
(man display)
Effettuo ora la decodifica del messaggio, estraendo quest'ultimo dall'immagine:
$ ./shadow-ass -d coded-im-orig.jpg
Image coded-im-orig.jpg opened in read mode
Message lenght: 79
Im going to decode: coded-im-orig.jpg
Message decoded:
Questo e' un fottuto messaggio di prova da inserire nell'immagine allora snado
TheAlchemist
L'ho provato solo da Linux. Da win non so se funziona.
Bella
E' un programma di steganografia, tramite il quale si inseriscono dei messaggi all'interno di immagini, senza che queste appaiano modificate in alcun modo.
Per capire il funzionamento basta vedere il pezzo di codice sotto //heart.
Considerate che sono un elettronico, quindi il mio codice puo' sembrare zozzo ai puristi
Il programma funziona con jpeg che impacchettano l'info ad 8 bit, quindi se non funziona con una immagine...provate con un'altra (magari vecchiotta gh), tanto internet e' piena di immagini da poter usare
/* This program shadows a message in an image (i prefer jpeg)
* If you have problems with an image, try with another one
*
* shadow-ass.c
* Coded by:
* TheAlchemist -> http://thealchemist-geek.tk
* I.M.G. Member -> http://www.inside-me.org
*
* Usage:
* o) 2 code: shadow-ass -c message.txt image.jpeg
* o) 2 decode: shadow-ass -d image.jpeg
*
* See you :)
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int lunghezza_mess(char *filem);
long lunghezza_ima(char *filei);
int preleva_dim(int *imm, int *st);
int code(int carattere, int state, int *imm, char *chiam, char *text, char *ack);
int decode(int *imm, int *st);
void usage(char *argom);
main(int argn, char **argv)
{
FILE *ima,*mes;
int a,stato,j,lenm,decchar;
long len;
char azione[2];
int *mess_bis, *imm_bis, car;
if(argn<3)
{
usage(argv[0]);
exit(-1);
}
strncpy(azione, argv[1], 3);
if(strstr(azione,"-c"))
{
lenm = lunghezza_mess(argv[2]);
len = lunghezza_ima(argv[3]);
if(len<(lenm*8 + 300))
{
printf("\nImage is too little!");
printf("\nTheAlchemist\n");
}
printf("\nImage lenght: %d",len);
printf("\nMessage lenght: %d",lenm);
stato=300;
if(argn<4)
usage(argv[0]);
imm_bis = malloc( (len * sizeof(int)) + 1 );
ima = fopen(argv[3], "r");
printf("\nImage %s opened in read mode",argv[3]);
for(j=0;j<len;j++)
{
imm_bis[j] = fgetc(ima);
if(imm_bis[j]==EOF)
break;
}
fclose(ima);
mess_bis = malloc( (lenm * sizeof(int)) + 2 );
mess_bis[0]=lenm;
mes = fopen(argv[2], "r");
for(j=1;j<len;j++)
{
mess_bis[j] = fgetc(mes);
if(mess_bis[j]==EOF)
break;
}
fclose(mes);
printf("\nMessage 2code: ");
for(j=1;j<=lenm;j++)
printf("%c",mess_bis[j]);
printf("\nI'm coding:");
for(a=0;a<lenm+1;a++)
{
car=mess_bis[a];
stato=code(car, stato, imm_bis, argv[0], argv[2], argv[3]);
}
printf("Coded!\nTheAlchemist\n");
}
else if(strstr(azione,"-d"))
{
stato=300;
len = lunghezza_ima(argv[2]);
imm_bis = malloc( (len * sizeof(int)) + 1 );
ima = fopen(argv[2], "r");
printf("\nImage %s opened in read mode",argv[2]);
for(j=0;j<len;j++)
{
imm_bis[j] = fgetc(ima);
if(imm_bis[j]==EOF)
break;
}
fclose(ima);
lenm = preleva_dim(imm_bis, &stato);
printf("\nMessage lenght: %d",lenm);
printf("\nIm going to decode: %s",argv[2]);
printf("\nMessage decoded:\n\n");
for(j=0;j<lenm;j++)
{
decchar=decode(imm_bis, &stato);
printf("%c",decchar);
}
printf("\n\nTheAlchemist\n");
}
else if(strstr(azione,"-h"))
{
usage(argv[0]);
}
else
{
printf("\nScelta non valida!\n");
usage(argv[0]);
}
}
int code(int carattere, int state, int *imm, char *chiam, char *text, char *ack)
{
FILE *fw;
char *afterfile, temp;
int namelen=strlen(ack),j,t;
long imagelen;
unsigned char mask;
afterfile = malloc( (namelen * sizeof(char)) + 6 );
strcpy(afterfile,"coded-");
strncat(afterfile, ack, namelen);
fw = fopen(afterfile, "w");
imagelen = lunghezza_ima(ack);
for(j=0;j<imagelen;j++)
{
fputc(imm[j],fw);
}
fseek(fw,(state * sizeof(int)),SEEK_SET);
//heart
mask=128;
t=0;
temp=0;
for(j=0;j<8;j++)
{
printf(".");
temp = carattere & mask;
temp = temp>>(7-t);
mask = mask>>1;
if(mask==0)
mask=80;
t++;
if(t==8)
t=0;
imm[state] = imm[state] & 254;
imm[state] = imm[state] | temp;
fputc(imm[state],fw);
state++;
}
fclose(fw);
return state;
}
int decode(int *imm, int *st)
{
int m, k, t, sum, temp, car;
unsigned char mask;
mask=01;
temp=0;
sum=0;
t=8;
for(m=0;m<8;m++)
{
temp = imm[(*st)] & mask;
t--;
temp = temp<<t;
if(t==0)
t=7;
sum = sum | temp;
(*st)++;
}
return sum;
}
void usage(char *argom)
{
printf("Usage: %s [option] <file> {image}", argom);
printf("\n\nOptions are:");
printf("\n\t-c\t: code a message => file is a textfile, image is the image where will be inserted the message");
printf("\n\t-d\t: decode a message => file is an image");
printf("\n\t-h\t: print this help");
printf("\n\nExample:");
printf("\ncoding a message: %s -c message.txt image",argom);
printf("\ndecoding a message: %s -d image",argom);
printf("\n\nTheAlchemist\n");
exit(-1);
}
int lunghezza_mess(char *filem)
{
FILE *mes;
int lenm;
mes = fopen(filem, "r");
if (fseek (mes,0L,SEEK_END) == 0)
{
lenm = ftell (mes);
rewind (mes);
}
fclose(mes);
return lenm;
}
long lunghezza_ima(char *filei)
{
FILE *ima;
long len;
ima = fopen(filei, "r");
if (fseek (ima,0L,SEEK_END) == 0)
{
len = ftell (ima);
rewind (ima);
}
fclose(ima);
return len;
}
int preleva_dim(int *imm, int *st)
{
int m, k, t, sum, temp, car;
unsigned char mask;
mask=01;
temp=0;
sum=0;
t=8;
for(m=0;m<8;m++)
{
temp = imm[(*st)] & mask;
t--;
temp = temp<<t;
if(t==0)
t=7;
sum = sum | temp;
(*st)++;
}
return sum;
}Esempio di utilizzo:
$ ./shadow-ass -h
Usage: ./shadow-ass [option] <file> {image}
Options are:
-c : code a message => file is a textfile, image is the image where will be inserted the message
-d : decode a message => file is an image
-h : print this help
Example:
coding a message: ./shadow-ass -c message.txt image
decoding a message: ./shadow-ass -d image
TheAlchemist
Metto il testo da iniettare nell'immagine in prova.txt ed effettuo la codifica:
$ ./shadow-ass -c prova.txt im-orig.jpg
Image lenght: 266876
Message lenght: 79
Image im-orig.jpg opened in read mode
Message 2code: Questo e' un fottuto messaggio di prova da inserire nell'immagine allora snado
I'm coding:.................................................................................................................................
.............................................................................................................................................
.............................................................................................................................................
.............................................................................................................................................
................................................................................Coded!
TheAlchemist
Il programma crea un clone dell'immagine im-orig.jpg, della stessa dimensione e con il prefisso "coded-"
$ ls -l
totale 932
-rw-r--r-- 1 x x 266876 2005-07-20 19:23 coded-im-orig.jpg
-rw-r--r-- 1 x x 266876 2005-07-19 14:11 im0000853xr.jpg
-rw-r--r-- 1 x x 266876 2005-07-19 13:47 im-orig.jpg
-rw-r--r-- 1 x x 79 2005-07-20 16:24 prova.txt
-rwxr-xr-x 1 x x 15599 2005-07-20 12:34 sa
-rwxr-xr-x 1 x x 15900 2005-07-20 16:33 sa2
-rw-r--r-- 1 x x 4970 2005-07-20 16:32 sa2.c
-rwxr-xr-x 1 x x 15911 2005-07-20 16:11 shadow-ass
-rw-r--r-- 1 x x 4571 2005-07-20 12:52 shadow-ass_0.5.c
-rw-r--r-- 1 x x 4942 2005-07-20 15:34 shadow-ass_0.6.c
-rw-r--r-- 1 x x 4673 2005-07-20 15:47 shadow-ass_1.0.c
-rw-r--r-- 1 x x 4968 2005-07-20 16:11 shadow-ass_1.1.c
-rwxr-xr-x 1 x x 15911 2005-07-20 16:33 shadow-ass_1.2
-rw-r--r-- 1 x x 4970 2005-07-20 16:33 shadow-ass_1.2.c
-rwxr-xr-x 1 x x 3997 2005-07-19 22:54 shadow-ass.c
-rwxr-xr-x 1 x x 3255 2005-07-19 20:20 shadow-ass.c.orig
-rw-r--r-- 1 x x 92 2005-07-20 15:55 voting_bar.gif
Potete vedere la straordinaria somiglianza tra le due foto, l'aver inserito il messaggio non si nota affatto!
(man display)
Effettuo ora la decodifica del messaggio, estraendo quest'ultimo dall'immagine:
$ ./shadow-ass -d coded-im-orig.jpg
Image coded-im-orig.jpg opened in read mode
Message lenght: 79
Im going to decode: coded-im-orig.jpg
Message decoded:
Questo e' un fottuto messaggio di prova da inserire nell'immagine allora snado
TheAlchemist
L'ho provato solo da Linux. Da win non so se funziona.
Bella
Si prega Accedi o Crea un account a partecipare alla conversazione.
18 Anni 11 Mesi fa #35402
da Matteo
Risposta da Matteo al topic Steganografia
Oltre alle decine di warning, dà segmentation fault.
Si prega Accedi o Crea un account a partecipare alla conversazione.
- Valentina Bragaglia
-
Autore della discussione
- Offline
- Elite Member
-
Riduci
Di più
- Messaggi: 207
- Ringraziamenti ricevuti 0
18 Anni 11 Mesi fa #35427
da Valentina Bragaglia
Risposta da Valentina Bragaglia al topic Steganografia
stranissimo, l'ho usato per un anno...
Si prega Accedi o Crea un account a partecipare alla conversazione.
- Valentina Bragaglia
-
Autore della discussione
- Offline
- Elite Member
-
Riduci
Di più
- Messaggi: 207
- Ringraziamenti ricevuti 0
18 Anni 11 Mesi fa #35432
da Valentina Bragaglia
Risposta da Valentina Bragaglia al topic Steganografia
1) In effetti da' segmentation fault, ma solo in fase di stampa della firma alla fine di ogni operazione, prova a dare uno `strace` del comando e te ne accorgi. Questo vuol dire che il programma funziona lo stesso, infatti ho preso una jpeg qualsiasi da kde-look.org e ho fatto un test...il programma funziona ancora benissimo...devo ammettere che e' strano che dia un deg.fault, prima non me lo dava...bha
2) non da' alcun warning, almeno compilato come lo compilo io:
$ gcc shadow-ass_1.2.c -o shadow
$
Fa la prova con questa immagine: www.kde-look.org/content/pre1/49859-1.jpg
e' quella che ho usato adesso per fare la prova.
$ ls *sfondo*
sfondo.jpg
$ ./shadow -c mess.txt sfondo.jpg
Image lenght: 71428
Message lenght: 5
Image sfondo.jpg opened in read mode
Message 2code: ciao
I'm coding:................................................Coded!
TheAlchemist
Segmentation fault
$ ls *sfondo*
coded-sfondo.jpg sfondo.jpg
$ ./shadow -d coded-sfondo.jpg
Image coded-sfondo.jpg opened in read mode
Message lenght: 5
Im going to decode: coded-sfondo.jpg
Message decoded:
ciao
TheAlchemist
Segmentation fault
Va in seg.fault ma funge
ghhghg
P.S. Ho notato che da root la codifica non va in seg.fault
2) non da' alcun warning, almeno compilato come lo compilo io:
$ gcc shadow-ass_1.2.c -o shadow
$
Fa la prova con questa immagine: www.kde-look.org/content/pre1/49859-1.jpg
e' quella che ho usato adesso per fare la prova.
$ ls *sfondo*
sfondo.jpg
$ ./shadow -c mess.txt sfondo.jpg
Image lenght: 71428
Message lenght: 5
Image sfondo.jpg opened in read mode
Message 2code: ciao
I'm coding:................................................Coded!
TheAlchemist
Segmentation fault
$ ls *sfondo*
coded-sfondo.jpg sfondo.jpg
$ ./shadow -d coded-sfondo.jpg
Image coded-sfondo.jpg opened in read mode
Message lenght: 5
Im going to decode: coded-sfondo.jpg
Message decoded:
ciao
TheAlchemist
Segmentation fault
Va in seg.fault ma funge
ghhghg
P.S. Ho notato che da root la codifica non va in seg.fault
Si prega Accedi o Crea un account a partecipare alla conversazione.