Lecture no.4
VirusandMalicious Code
MaliciousCode
►Malicious code can be a program or part of a program; a
programpartcanevenattachitselfto another(good)program
so that malicious effect occurs whenever the good program
runs.
►Malicious code can do anything other program can such as
writing a message on a computer screen, stopping a running
program,generatingasound orerasingastoredfile– malicious
codecaneven donothingatall.
MaliciousCode
So…..
► Whatisamaliciouscode?
► Howcanittakecontrolofasystem?
► Howcanitlodgeinasystem?
► Howdoesmaliciouscodespread?
► Howcanitberecognized?
► Howcanitbestopped?
MaliciousCode
Types of Malicious Code
► Virus – attachitselftoprogramandpropagatescopiesof itselftootherprograms.
► Trojan Horse – containunexpected,additionalfunctionality.
► Logic bomb – triggersactionwhenconditionoccur.
► Time bomb - triggersactionwhenspecifictimeoccur.
► Trapdoor – allowsunauthorizedaccesstofunctionality.
► Worm – propagatescopiesofitselfthroughnetwork.
► Rabbit – asavirusorwormreplicatesitselfwithoutlimittoexhaustresources.
Virus
► Avirus
Aprogramthatpassonmaliciouscodetoothernonmalicious(program)
bymodifyingthem.
Similartobiologicalvirus,itinfectshealthysubjects
Infectsaprogrambyattachingtheprogram
►Destroytheprogramorcoexistwithit.
►Agoodprogram,onceinfectedbecomesa carrierandinfectsother
program.
►Eithertransientorresident(standalone).
TrojanHorse
►TrojanHorse
Amaliciouscode,inadditiontoprimaryeffect,ithasamalicious effect.
Example 1: a login scripts that solicits a user’s identification and
password,passestheinfotothesystemforloggingprocessingandkeeps
a copyformalicious purpose.
Example2:acatcommandthatdisplaystextandsendsacopyofthe
texttosomewhereelse.
Trapdoor
► Trapdoor/backdoor
Afeatureinaprogrambywhichsomeonecanaccesstheprogram
usingspecialprivilege.
e.g.A
TMprovides990099toexecutesomething
Worm
►Worm
Spreadcopiesofitselfthroughanetwork.
Wormthroughnetworkandvirusthroughothermedium.
Spreaditselfasastand-aloneprogram.
Trapdoors
► Asecret,undocumentedentrypointintoamodulewhichallowsaspecializedaccess.
► Thetrapdoorisinsertedduringcodedevelopment
Testthemodules,allowaccessineventsoferror
► Trapdoorarevulnerabilitiesbecausetheyexposethesystemtomodificationduring
execution.
► Theprogrammerusuallyremovestrapdoorsduring programdevelopment.
Butsometimes,
becomes
forgettoremovethem
leavesthemintheprogramfortestingandmaintenanceorasacovertmeansofaccessto
theroutineafterit
anacceptedproductionprogram.
Trapdoors
► Itcanbeusedbyanyonewhodiscoversthetrapdoorby accidentorexhaustivetrials.
► Examplesoftrapdoorsinprogramdevelopmentwhichcanbeabused
Debugging/testingsoftwaremodulesusingdriversandstubsand debugcontrolsequences
Poorqualityprogram,e.guseofCASEstatementwhichcapturesall“defaults”
Unusedopcodesinhardwaredesignwhichcanbeexploitedtodo otherundocumentedthings
► Trapdoorsaregenerallydesirableinprogramdevelopment
auditorsintroducefictitioustransactionandtracetheeffect
importantforprogram maintenance
HowVirusesAttach?
(1) Appended Virus
Original
Progra
m
+ Virus code = Original
Progra
m
Viruscode
HowVirusesAttach?
(1) AppendedViruses
►Avirusattachesitselftoaprogram.
►Whenevertheprogramruns,thevirusis activated.
►Avirussimplyinsertsacopyofitselfintotheprogramfilebeforethe
firstexecutableinstruction,sothatallthevirusinstructionare
completelyexecutedandthenfollowedbytherealprogram
instruction.
HowVirusesAttach?
(2) Virusesthatsurrounda program
Virus code Original
Program
Virus code
(Part a)
Original
program
Virus code
(part b)
This kind of virus that runs the original program but has control
before and after its execution.
HowVirusesAttach?
(3) IntegratedVirusesandReplacement
Original
Program
+
Virus
Code =
Modified
program
HowVirusesAttach?
(3) IntegratedVirusesandReplacement
► Avirusmightreplacesomeofitstarget,integratingitselfintotheoriginalcodeof
thetarget.
► Finally,theviruscanreplacetheentiretarget,eithermimickingtheeffectofthe
targetorignoring theexpectedeffectofthetargetandperformingonlythe
viruseffect.
HowVirusesGainControl?
(1) Overwriting Target
T T
File Directory
A) Overwriting
T
V
V
Disk storage
Before
After
HowVirusesGainControl?
(1) OverwritingTarget
► Thevirus(V)hastobeinvokedinsteadofthetarget(T).
► Thevirus(V)eitherhastobeseentobeT,saying effectively“I’mT”
► Orthevirus(V)hastopushToutofthewayand becomeasubstituteforT,
sayingeffectively“callmeinsteadofT”
HowVirusesGainControl?
(2) Changing Pointers
T T
B ) Changing Pointer
T
V
T
V
The virus change the pointers in the file table so that V is located
instead of T whenever T is accessed through the file system.
Homefor Viruses
Boot Sector Viruses
► Aspecialcaseofvirusattachment,butafairlyapopular one.
► Whenacomputerisstarted,controlstartwithafirmwarethatdetermineswhichhardware
componentsarepresent, testthemandtransfercontroltoOS.
► TheOSissoftwarestoredondisk.TheOShastostartwithcodethatcopiesitfromdiskto
memoryandtransfers controltoit,calledbootstrapload.
► Booting:Thefirmwarereadthebootsector(afixedlocationontheh/disk)toafixedlocation
onmemoryandjumptotheaddressthatcontainbootstrap loader.
Homefor Viruses
► TheloaderloadtheOStothememory.
► BootsectoronPCislessthan512byte
► Chainingisusedtosupportbig bootstrap
► Thismechanismcanbeutilizedbyvirusinstallation
► Viruswritercanbreakthechainandpointtotheviruscodeandreconnectthechainaftervirus
installation
► Theadvantage:virusgainscontrolearlyduringthebootprocess.
► Hidinginthebootareawhichisnotaccessiblebyusers.
Homefor Viruses
Bootstrap
loader
System
initialize
Bootstrap
loader
System
initialize
Virus code
Before Infection
After Infection
Boot Sector
Boot Sector
Other sectors
Other sectors
Homefor Viruses
Avirus can:
►
►
►
attachitselftothesystemfilesIO.SYSor MSDOS.SYS
attachitselftoanyotherprogramloaded becauseofanentryin
CONFIG.SYSorAUTOEXEC.BA
Tor
addanentrytoCONFIG>SYSor
AUTOEXEC.BA
Ttocauseittobe loaded
► Example:CIHvirus,BRAIN virus
Homefor Viruses
Memory-Resident Viruses
► SomepartofOSorprogramexecute,terminateand disappears,withtheirspacein
memorybeingavailablefor anythingexecutedlater.
► Frequentlyusedcoderemaininspecialmemoryandis called“residentcode”or
TSR.
► Viruswritersalsoliketoattachvirusestoresidentcodebecauseitisactivatedmanytimes
whilethemachineis running.
► Eachtimetheresidentcoderuns,thevirusdoestoo
► Onceactivated,theviruscanlookforandinfectuninfectedcarrier
► Virusmaytargettheuninfecteddiskette.
Homefor Viruses
Other Homes For Viruses
► Apopularhomeforvirusesisanapplicationprogram.
► WordProcessingandspreadsheethasamacrowhereusersmayrecordaseriesof
commandswithasingleinvocation
► Writermaycreateastartupmacrothatcontainsvirus
► Italsoembedsacopyofitselfindatafilessothattheinfectionspreadtoanyone
receivingit
► Librariesarealsoexcellentplacesforviruses.Becauseitis usedbymanyprogramandthus
thecodeinthemhas broadeffectandalsosharedbetween users
VirusSignature
►
►
►
Aviruscodecannotbecompletelyinvisible. Codemustbeinmemory
tobeexecuted.
Viruseshastheirowncharacteristic/behavior– signature
(1) Storagepattern- virusesthatattachtoprogramsthatarestoredondisks.
Theattachedviruspieceisinvariant,sothatthestartoftheviruscode
becomesa detectablesignature.
SmallportionbutJUMPtovirusmodule
VirusSignature
(2) ExecutionPattern
► Aviruswritermaywantavirustodoseveralthings:
spreadinfection
avoiddetection
causeharm-
Theharmthataviruscancauseisunlimited
►
►
►
►
►
Donothing
DisplaymessageonthescreenPlaymusic
Erasefile/entirediskPrevent
booting
Writingontheh/disk
VirusSignature
(3) Transmissionpattern
► Avirusalsohastohavesomemeansof transmissionfrom
onedisktoanother
► Virusescantravelduringthebootprocess,withan executablefile,orindata
files.
► Virusestravelduringexecutionofaninfectedprogram.
► Becauseaviruscanexecuteanyinstructiona programcan,virustravelis
notconfinedtoany singlemediumorexecutionpattern.
VirusSignature
(4)PolymorphicViruses
►Isavirusthatcanchangeitsappearance.
►“Poly”means“many”and“morph”means“form”.
►Toavoiddetection,noteverycopyofa polymorphicvirushas
todifferfromevery othercopy.
Preventing Virus
► Useonlycommercialsoftwareacquiredfromreliable,well
establishedvendors.
► Testallnewsoftwareonanisolatedcomputers.
► Makeabootablediskettesandstoreitsafely- writeprotectbefore
booting
► Makeandretainbackupcopiesofexecutablesystemfiles.
► Usevirusdetectors regularly.
► Don’ttrustanysourcefromoutsideuntilitsbeen testfirst.

5virusandmaliciouscodechapter5-130716024935-phpapp02-converted.pptx