Violent Python - TJ O Connor
269 pág.

Violent Python - TJ O Connor


DisciplinaProgramação de Script10 materiais183 seguidores
Pré-visualização50 páginas
Violent Python
A Cookbook for Hackers, 
Forensic Analysts, 
Penetration Testers and 
Security Engineers
!-34%2$!-\ufffds\ufffd"/34/.\ufffds\ufffd(%)$%,"%2'\ufffds\ufffd,/.$/.
.%7\ufffd9/2+\ufffds\ufffd/8&/2$\ufffds\ufffd0!2)3\ufffds\ufffd3!.\ufffd$)%'/
3!.\ufffd&2!.#)3#/\ufffds\ufffd3).'!0/2%\ufffds\ufffd39$.%9\ufffds\ufffd4/+9/\ufffd
 
3YNGRESS\ufffdIS\ufffdAN\ufffd)MPRINT\ufffdOF\ufffd%LSEVIER
TJ. O\u2019Connor
Violent Python
A Cookbook for Hackers, 
Forensic Analysts, 
Penetration Testers and 
Security Engineers
Acquiring Editor: Chris Katsaropoulos
Development Editor: Meagan White
Project Manager: Priya Kumaraguruparan
Designer: Russell Purdy
Syngress is an imprint of Elsevier
225 Wyman Street, Waltham, MA 02451, USA
Copyright © 2013 Elsevier, Inc. All rights reserved.
No part of this publication may be reproduced or transmitted in any form or by any means, 
electronic or mechanical, including photocopying, recording, or any information storage and 
retrieval system, without permission in writing from the publisher. Details on how to seek 
permission, further information about the Publisher\u2019s permissions policies and our arrange-
ments with organizations such as the Copyright Clearance Center and the Copyright Licensing 
Agency, can be found at our website: www.elsevier.com/permissions.
This book and the individual contributions contained in it are protected under copyright by the 
Publisher (other than as may be noted herein).
Notices
Knowledge and best practice in this !eld are constantly changing. As new research and experi-
ence broaden our understanding, changes in research methods or professional practices, may 
become necessary. Practitioners and researchers must always rely on their own experience and 
knowledge in evaluating and using any information or methods described herein. In using such 
information or methods they should be mindful of their own safety and the safety of others, 
including parties for whom they have a professional responsibility.
To the fullest extent of the law, neither the Publisher nor the authors, contributors, or editors, 
assume any liability for any injury and/or damage to persons or property as a matter of products 
liability, negligence or otherwise, or from any use or operation of any methods, products, 
instructions, or ideas contained in the material herein.
Library of Congress Cataloging-in-Publication Data
Application submitted
British Library Cataloguing-in-Publication Data
A catalogue record for this book is available from the British Library.
ISBN: 978-1-59749-957-6
Printed in the United States of America
13 14 15 10 9 8 7 6 5 4 3 2 1
 For information on all Syngress publications visit our website at www.syngress.com
v
Trademarks
%LSEVIER\ufffd\ufffd )NC\ufffd\ufffd\ufffd THE\ufffdAUTHOR\ufffdS	\ufffd\ufffdAND\ufffdANY\ufffdPERSON\ufffdOR\ufffdlRM\ufffdINVOLVED\ufffdIN\ufffdTHE\ufffdWRITING\ufffd\ufffd
EDITING\ufffd\ufffdOR\ufffdPRODUCTION\ufffd\ufffdCOLLECTIVELY\ufffdh-AKERSv	\ufffdOF\ufffd THIS\ufffdBOOK\ufffd\ufffdhTHE\ufffd7ORKv	\ufffdDO\ufffd
NOT\ufffdGUARANTEE\ufffdOR\ufffdWARRANT\ufffdTHE\ufffdRESULTS\ufffdTO\ufffdBE\ufffdOBTAINED\ufffdFROM\ufffdTHE\ufffd7ORK\ufffd
4HERE\ufffdIS\ufffdNO\ufffdGUARANTEE\ufffdOF\ufffdANY\ufffdKIND\ufffd\ufffdEXPRESSED\ufffdOR\ufffdIMPLIED\ufffd\ufffdREGARDING\ufffdTHE\ufffd7ORK\ufffdOR\ufffd
ITS\ufffdCONTENTS\ufffd\ufffd4HE\ufffd7ORK\ufffdIS\ufffdSOLD\ufffd!3\ufffd)3\ufffdAND\ufffd7)4(/54\ufffd7!22!.49\ufffd\ufffd9OU\ufffdMAY\ufffdHAVE\ufffd
OTHER\ufffdLEGAL\ufffdRIGHTS\ufffd\ufffdWHICH\ufffdVARY\ufffdFROM\ufffdSTATE\ufffdTO\ufffdSTATE\ufffd
)N\ufffdNO\ufffdEVENT\ufffdWILL\ufffd-AKERS\ufffdBE\ufffd LIABLE\ufffd TO\ufffdYOU\ufffdFOR\ufffdDAMAGES\ufffd\ufffd INCLUDING\ufffdANY\ufffd LOSS\ufffdOF\ufffd
PROlTS\ufffd\ufffdLOST\ufffdSAVINGS\ufffd\ufffdOR\ufffdOTHER\ufffdINCIDENTAL\ufffdOR\ufffdCONSEQUENTIAL\ufffdDAMAGES\ufffdARISING\ufffdOUT\ufffd
FROM\ufffdTHE\ufffd7ORK\ufffdOR\ufffdITS\ufffdCONTENTS\ufffd\ufffd"ECAUSE\ufffdSOME\ufffdSTATES\ufffdDO\ufffdNOT\ufffdALLOW\ufffdTHE\ufffdEXCLUSION\ufffd
OR\ufffd LIMITATION\ufffdOF\ufffd LIABILITY\ufffd FOR\ufffdCONSEQUENTIAL\ufffdOR\ufffd INCIDENTAL\ufffdDAMAGES\ufffd\ufffd THE\ufffdABOVE\ufffd
LIMITATION\ufffdMAY\ufffdNOT\ufffdAPPLY\ufffdTO\ufffdYOU\ufffd
9OU\ufffdSHOULD\ufffdALWAYS\ufffdUSE\ufffdREASONABLE\ufffdCARE\ufffd\ufffdINCLUDING\ufffdBACKUP\ufffdAND\ufffdOTHER\ufffdAPPROPRI-
ATE\ufffdPRECAUTIONS\ufffd\ufffdWHEN\ufffdWORKING\ufffdWITH\ufffdCOMPUTERS\ufffd\ufffdNETWORKS\ufffd\ufffdDATA\ufffd\ufffdAND\ufffdlLES\ufffd
3YNGRESS\ufffd -EDIAš\ufffd\ufffd 3YNGRESSš\ufffd\ufffd h#AREER\ufffd !DVANCEMENT\ufffd 4HROUGH\ufffd 3KILL\ufffd %NHANCE-
MENTš\ufffdv\ufffd h!SK\ufffd THE\ufffd !UTHOR\ufffd 50$!4%š\ufffdv\ufffd AND\ufffd h(ACK\ufffd 0ROOlNGš\ufffdv\ufffd ARE\ufffd REGISTERED\ufffd
TRADEMARKS\ufffd OF\ufffd %LSEVIER\ufffd\ufffd )NC\ufffdh3YNGRESS\ufffd4HE\ufffd $ElNITION\ufffd OF\ufffd A\ufffd 3ERIOUS\ufffd 3ECURITY\ufffd
,IBRARYv4-\ufffd\ufffdh-ISSION\ufffd#RITICAL4-\ufffdv\ufffdAND\ufffdh4HE\ufffd/NLY\ufffd7AY\ufffdTO\ufffd3TOP\ufffdA\ufffd(ACKER\ufffdIS\ufffdTO\ufffd
4HINK\ufffd,IKE\ufffd/NE4-v\ufffdARE\ufffdTRADEMARKS\ufffdOF\ufffd%LSEVIER\ufffd\ufffd)NC\ufffd\ufffd"RANDS\ufffdAND\ufffdPRODUCT\ufffdNAMES\ufffd
MENTIONED\ufffd IN\ufffd THIS\ufffd BOOK\ufffd ARE\ufffd TRADEMARKS\ufffd OR\ufffd SERVICE\ufffdMARKS\ufffd OF\ufffd THEIR\ufffd RESPECTIVE\ufffd
COMPANIES\ufffd
ix
Dedication
For my monkey and my ninja princess: anything is 
possible if you try hard enough.
xvii
Lead Author \u2013 TJ O\u2019Connor
4*\ufffd/\ufffd#ONNOR\ufffdIS\ufffdA\ufffd$EPARTMENT\ufffdOF\ufffd$EFENSE\ufffdEXPERT\ufffdON\ufffdINFORMATION\ufffdSECURITY\ufffdAND\ufffd
A\ufffd53\ufffd!RMY\ufffdPARATROOPER\ufffd\ufffd7HILE\ufffd ASSIGNED\ufffd AS\ufffd AN\ufffd ASSISTANT\ufffd PROFESSOR\ufffd AT\ufffd THE\ufffd53\ufffd
-ILITARY\ufffd !CADEMY\ufffd\ufffd 4*\ufffd TAUGHT\ufffd UNDERGRADUATE\ufffd COURSES\ufffd ON\ufffd FORENSICS\ufffd\ufffd EXPLOITA-
TION\ufffd AND\ufffd INFORMATION\ufffd ASSURANCE\ufffd\ufffd(E\ufffd TWICE\ufffd CO
COACHED\ufffd THE\ufffdWINNING\ufffd TEAM\ufffd AT\ufffd
THE\ufffd.ATIONAL\ufffd 3ECURITY\ufffd!GENCY\ufffdS\ufffd ANNUAL\ufffd#YBER\ufffd$EFENSE\ufffd%XERCISE\ufffd AND\ufffdWON\ufffd THE\ufffd
.ATIONAL\ufffd$EFENSE\ufffd5NIVERSITY\ufffdS\ufffdlRST\ufffdANNUAL\ufffd#YBER\ufffd#HALLENGE\ufffd\ufffd(E\ufffdHAS\ufffdSERVED\ufffdON\ufffd
MULTIPLE\ufffdRED\ufffdTEAMS\ufffd\ufffdINCLUDING\ufffdTWICE\ufffdON\ufffdTHE\ufffd.ORTHEAST\ufffd2EGIONAL\ufffd4EAM\ufffdFOR\ufffdTHE\ufffd
.ATIONAL\ufffd#OLLEGIATE\ufffd#YBER\ufffd$EFENSE\ufffd#OMPETITION\ufffd\ufffd
4*\ufffdHOLDS\ufffdA\ufffd-ASTER\ufffdOF\ufffd3CIENCE\ufffdDEGREE\ufffdIN\ufffd#OMPUTER\ufffd3CIENCE\ufffdFROM\ufffd.ORTH\ufffd#AROLINA\ufffd
3TATE\ufffd\ufffd A\ufffd-ASTER\ufffd OF\ufffd 3CIENCE\ufffd DEGREE\ufffd IN\ufffd )NFORMATION\ufffd 3ECURITY\ufffd %NGINEERING\ufffd FROM\ufffd
THE\ufffd3!.3\ufffd4ECHNICAL\ufffd)NSTITUTE\ufffd\ufffdAND\ufffdA\ufffd"ACHELOR\ufffdOF\ufffd3CIENCE\ufffdDEGREE\ufffdIN\ufffd#OMPUTER\ufffd
3CIENCE\ufffdFROM\ufffdTHE\ufffd53\ufffd-ILITARY\ufffd!CADEMY\ufffd\ufffd(E\ufffdHAS\ufffdPUBLISHED\ufffdTECHNICAL\ufffdRESEARCH\ufffdAT\ufffd
53%.)8\ufffdWORKSHOPS\ufffd\ufffd!#-\ufffdCONFERENCES\ufffd\ufffdSECURITY\ufffdCONFERENCES\ufffd\ufffdTHE\ufffd3!.3\ufffd2EAD-
ING\ufffd2OOM\ufffd\ufffdTHE\ufffd)NTERNET\ufffd3TORM\ufffd#ENTER\ufffd\ufffdTHE\ufffdArmy Magazine\ufffd\ufffdAND\ufffdTHE\ufffdArmed Forces 
Journal\ufffd\ufffd(E\ufffdHOLDS\ufffdEXPERT\ufffd CYBER\ufffd SECURITY\ufffdCREDENTIALS\ufffd\ufffd INCLUDING\ufffd THE\ufffdPRESTIGIOUS\ufffd
')!#\ufffd3ECURITY\ufffd%XPERT\ufffd\ufffd'3%	\ufffdAND\ufffd/FFENSIVE\ufffd3ECURITY\ufffd#ERTIlED\ufffd%XPERT\ufffd\ufffd/3#%	\ufffd\ufffd 
4*\ufffdIS\ufffdA\ufffdMEMBER\ufffdOF\ufffdTHE\ufffdELITE\ufffd3!.3\ufffd2ED\ufffdAND\ufffd"LUE\ufffd4EAM\ufffd#YBER\ufffd'UARDIANS\ufffd
xix
Contributing Author Bio \u2013 Rob Frost
2OBERT\ufffd &ROST\ufffd GRADUATED\ufffd FROM\ufffd THE\ufffd 5NITED\ufffd 3TATES\ufffd -ILITARY\ufffd !CADEMY\ufffd IN\ufffd \ufffd\ufffd\ufffd\ufffd\ufffd\ufffd
COMMISSIONING\ufffdINTO\ufffdTHE\ufffd!RMY\ufffd3IGNAL\ufffd#ORPS\ufffd\ufffd(E\ufffdHOLDS\ufffdA\ufffd"ACHELOR\ufffdOF\ufffd3CIENCE\ufffd
DEGREE\ufffd IN\ufffd#OMPUTER\ufffd 3CIENCE\ufffdWITH\ufffdHONORS\ufffd\ufffdWITH\ufffdHIS\ufffd THESIS\ufffdWORK\ufffd FOCUSING\ufffdON\ufffd
OPEN
SOURCE\ufffdINFORMATION
GATHERING\ufffd\ufffd2OB\ufffdWAS\ufffdINDIVIDUALLY\ufffdRECOGNIZED\ufffdAS\ufffdONE\ufffdOF\ufffd
THE\ufffdTOP\ufffdTWO\ufffdMEMBERS\ufffdOF\ufffdTHE\ufffdNATIONAL\ufffdCHAMPIONSHIP\ufffdTEAM\ufffdFOR\ufffdTHE\ufffd\ufffd\ufffd\ufffd\ufffd\ufffd#YBER\ufffd
$EFENSE\ufffd%XERCISE\ufffdDUE\ufffdTO\ufffdHIS\ufffdABILITY\ufffdTO\ufffdCIRCUMVENT\ufffdRULES\ufffd\ufffd2OB\ufffdHAS\ufffdPARTICIPATED\ufffdIN\ufffd
AND\ufffdWON\ufffdSEVERAL\ufffdCYBER\ufffdSECURITY\ufffdCOMPETITIONS\ufffd\ufffd\ufffd
xxi
Technical Editor Bio \u2013 Mark Baggett
-ARK\ufffd"AGGETT\ufffdIS\ufffdA\ufffd#ERTIlED\ufffd3!.3\ufffd)NSTRUCTOR\ufffdAND\ufffdTEACHES\ufffdSEVERAL\ufffdCOURSES\ufffdIN\ufffdTHE\ufffd
3!.3\ufffd PENETRATION\ufffd TESTING\ufffd CURRICULUM\ufffd\ufffd -ARK\ufffd IS\ufffd THE\ufffd PRIMARY\ufffd CONSULTANT\ufffd AND\ufffd
FOUNDER\ufffd OF\ufffd )N\ufffd $EPTH\ufffd $EFENSE\ufffd\ufffd )NC\ufffd\ufffd\ufffd WHICH\ufffd PROVIDES\ufffd INCIDENT
RESPONSE\ufffd AND\ufffd
PENETRATION
TESTING\ufffdSERVICES\ufffd\ufffd4ODAY\ufffd\ufffdIN\ufffdHIS\ufffdROLE\ufffdAS\ufffdTHE\ufffdTECHNICAL\ufffdADVISOR\ufffdTO\ufffdTHE\ufffd
$EPARTMENT\ufffdOF\ufffd$EFENSE\ufffdFOR\ufffd3!.3\ufffd\ufffd-ARK\ufffdIS\ufffdFOCUSED\ufffdON\ufffdTHE\ufffdPRACTICAL\ufffdAPPLICATION\ufffd
OF\ufffd3!.3\ufffdRESOURCES\ufffdIN\ufffdTHE\ufffdDEVELOPMENT\ufffdOF\ufffdMILITARY\ufffdCAPABILITIES\ufffd\ufffd
-ARK\ufffdHAS\ufffdHELD\ufffdA\ufffdVARIETY\ufffdOF\ufffdPOSITIONS\ufffdIN\ufffdINFORMATION\ufffdSECURITY\ufffdFOR\ufffdLARGE\ufffdINTERNA-
TIONAL\ufffdAND\ufffd&ORTUNE\ufffd\ufffd\ufffd\ufffd\ufffd\ufffdCOMPANIES\ufffd\ufffd(E\ufffdHAS\ufffdBEEN\ufffdA\ufffdSOFTWARE\ufffdDEVELOPER\ufffd\ufffdA\ufffdNET-
WORK\ufffdAND\ufffdSYSTEMS\ufffdENGINEER\ufffd\ufffdA\ufffdSECURITY\ufffdMANAGER\ufffd\ufffdAND\ufffdA\ufffd#)3/\ufffd\ufffd!S\ufffdA\ufffd#)3/\ufffd\ufffd-ARK\ufffd
WAS\ufffdRESPONSIBLE\ufffdFOR\ufffdPOLICY\ufffd\ufffdCOMPLIANCE\ufffd\ufffdINCIDENT\ufffdRESPONSE\ufffd\ufffdAND\ufffdALL\ufffdOTHER\ufffdASPECTS\ufffd
OF\ufffdINFORMATION\ufffdSECURITY\ufffdOPERATIONS\ufffd\ufffd-ARK\ufffdKNOWS\ufffdlRSTHAND\ufffdTHE\ufffdCHALLENGES\ufffdTHAT\ufffd
INFORMATION\ufffd SECURITY\ufffdPROFESSIONALS\ufffd FACE\ufffd TODAY\ufffd IN\ufffd SELLING\ufffd\ufffd IMPLEMENTING\ufffd\ufffd AND\ufffd
SUPPORTING\ufffdINFORMATION\ufffdSECURITY\ufffd\ufffd-ARK\ufffdIS\ufffdAN\ufffdACTIVE\ufffdMEMBER\ufffdOF\ufffdTHE\ufffdINFORMATION\ufffd
SECURITY\ufffdCOMMUNITY\ufffdAND\ufffdTHE\ufffdFOUNDING\ufffdPRESIDENT\ufffdOF\ufffdTHE\ufffd'REATER\ufffd!UGUSTA\ufffd)33!\ufffd\ufffd
(E\ufffdHOLDS\ufffdSEVERAL\ufffdCERTIlCATIONS\ufffd\ufffdINCLUDING\ufffd3!.3\ufffd\ufffdPRESTIGIOUS\ufffd'3%\ufffd\ufffd-ARK\ufffdBLOGS\ufffd
ABOUT\ufffdVARIOUS\ufffdSECURITY\ufffdTOPICS\ufffdAT\ufffdHTTP\ufffd\ufffd\ufffdWWW\ufffdPAULDOTCOM\ufffdCOM\ufffd
xxiii
Introduction
0YTHON\ufffd IS\ufffdA\ufffdHACKER\ufffdS\ufffd LANGUAGE\ufffd\ufffd7ITH\ufffd ITS\ufffdDECREASED\ufffdCOMPLEXITY\ufffd\ufffd INCREASED\ufffdEFl-
CIENCY\ufffd\ufffdLIMITLESS\ufffdTHIRD
PARTY\ufffdLIBRARIES\ufffd\ufffdAND\ufffdLOW\ufffdBAR\ufffdTO\ufffdENTRY\ufffd\ufffd0YTHON\ufffdPROVIDES\ufffdAN\ufffd
EXCELLENT\ufffdDEVELOPMENT\ufffdPLATFORM\ufffdTO\ufffdBUILD\ufffdYOUR\ufffdOWN\ufffdOFFENSIVE\ufffdTOOLS\ufffd\ufffd)F\ufffdYOU\ufffdARE\ufffd
RUNNING\ufffd-AC\ufffd/3\ufffd8\ufffdOR\ufffd,INUX\ufffd\ufffdODDS\ufffdARE\ufffdIT\ufffd IS\ufffdALREADY\ufffdINSTALLED\ufffdON\ufffdYOUR\ufffdSYSTEM\ufffd\ufffd
7HILE\ufffdA\ufffdWEALTH\ufffdOF\ufffdOFFENSIVE\ufffdTOOLS\ufffdALREADY\ufffdEXIST\ufffd\ufffdLEARNING\ufffd0YTHON\ufffdCAN\ufffdHELP\ufffdYOU\ufffd
WITH\ufffdTHE\ufffdDIFlCULT\ufffdCASES\ufffdWHERE\ufffdTHOSE\ufffdTOOLS\ufffdFAIL\ufffd\ufffd
TARGET AUDIENCE
%VERYONE\ufffdLEARNS\ufffdDIFFERENTLY\ufffd\ufffd(OWEVER\ufffd\ufffdWHETHER\ufffdYOU\ufffdARE\ufffdA\ufffdBEGINNER\ufffdWHO\ufffdWANTS\ufffd