$kernel.infect(): Creating a cryptovirus for Symfony2 apps
This is a modal window.
The media could not be loaded, either because the server or network failed or because the format is not supported.
Formal Metadata
Title |
| |
Title of Series | ||
Part Number | 14 | |
Number of Parts | 59 | |
Author | ||
License | CC Attribution - NonCommercial 2.0 Germany: You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal and non-commercial purpose as long as the work is attributed to the author in the manner specified by the author or licensor. | |
Identifiers | 10.5446/19625 (DOI) | |
Publisher | ||
Release Date | ||
Language |
Content Metadata
Subject Area | ||
Genre | ||
Abstract |
| |
Keywords |
FrOSCon 201414 / 59
1
2
3
4
8
11
21
23
26
29
30
34
35
36
37
38
39
41
42
43
45
46
50
52
53
54
56
57
58
00:00
Mobile appOpen sourceFreewareOpen setKernel (computing)Software developerComputerPolymorphism (materials science)Observational studyCryptographySoftwareInformation retrievalOrder (biology)Computer virusArithmetic meanBitSoftware developerTheorySoftware testingRight angleMultiplication signLine (geometry)VarianceWebsiteMathematical analysisInformationObservational studyStress (mechanics)Computer scienceStrategy gameEndliche ModelltheoriePoint (geometry)View (database)Network topologyFile format1 (number)Information retrievalCryptographyComputerMalwareDegree (graph theory)MereologyField (computer science)Hash functionFundamental theorem of algebraBlock (periodic table)SharewareKernel (computing)XMLUML
03:28
Computer virusProof theorySoftware frameworkComputerHacker (term)Server (computing)Mobile appPasswordIntercept theoremBackdoor (computing)INTEGRALProof theoryPredicate (grammar)InformationState of matterSequenceSubject indexingGoodness of fitExtension (kinesiology)Set (mathematics)Cellular automatonDistanceLevel (video gaming)Right angleInterface (computing)Interpreter (computing)Computer virusEvent horizonPublic-key cryptographySummierbarkeitOrder (biology)SphereSoftware maintenanceConnected spaceFlow separationResultantMereologyFocus (optics)Execution unitNeuroinformatikInformation securityPhysical systemKey (cryptography)SpacetimeServer (computing)Hacker (term)Computer fileLoginPasswordCartesian coordinate systemBootstrap aggregatingDatabaseService (economics)Mobile appInformation retrievalKernel (computing)Web pageCodeElectronic mailing listSharewareDifferent (Kate Ryan album)Computer animationXMLUML
08:12
CryptographyKey (cryptography)Function (mathematics)Diskreter LogarithmusFactorizationInverse elementCurveMultiplicationOpen sourceTransport Layer SecurityExtension (kinesiology)Library (computing)System programmingRevision controlVulnerability (computing)Read-only memoryMereologyPublic-key cryptographyKey (cryptography)DivisorDifferent (Kate Ryan album)Medical imagingCuboidoutputCalculationArithmetic meanLengthFunctional (mathematics)InformationMultiplicationFunction (mathematics)Numbering schemeSelf-organizationLogarithmQuery languagePhysical systemOpen setComputer fileInterior (topology)Workstation <Musikinstrument>EmailProcess (computing)NeuroinformatikSound effectPrice indexDivision (mathematics)Cellular automatonSpeech synthesisResultantMultiplication signSocial classSequelDistanceComputer animationProgram flowchart
13:24
Key (cryptography)EncryptionInformationSocial classPublic-key cryptographyEndliche ModelltheorieTask (computing)Functional (mathematics)Source codeXML
14:16
Semiconductor memoryService (economics)Set (mathematics)Computer virusPattern recognitionComputer animation
15:03
Kernel (computing)Event horizonGame controllerDependent and independent variablesCache (computing)Operations researchInterface (computing)Computer fileInterface (computing)Standard deviationComputer fileBootstrap aggregatingKernel (computing)Software frameworkCartesian coordinate systemComponent-based software engineeringMultiplication signClient (computing)Type theoryInformationObject (grammar)Event horizonDependent and independent variablesEmailCASE <Informatik>Proper mapEvent-driven programmingException handlingPasswordGame controllerProcess (computing)MereologySocial classCodeProduct (business)Form (programming)AuthorizationWater vaporRootDemosceneLocal ringRight angleGradientCuboidBasis <Mathematik>Set (mathematics)Student's t-testNegative numberMetropolitan area networkOptimization problemFunctional (mathematics)Computer animationProgram flowchart
20:05
Computer virusAntivirus softwareSoftwareComputer filePhysical systemMalwareHeuristicKernel (computing)Event horizonComputer networkServer (computing)Fiber bundleComputer fileWeb 2.0Bootstrap aggregatingCache (computing)Event horizonPlanningPattern recognitionWeb serviceComputer animationXML
21:13
Computer virusAntivirus softwareSoftwareComputer filePhysical systemMalwareHeuristicComputer networkKernel (computing)Event horizonSystem callCodeCodeMachine codePolymorphism (materials science)EmulatorLogical constantAbstract syntax treeOpcodeComputer-assisted translationComputerNumbering schemeTask (computing)Electric generatorRandom numberObservational studyAntivirus softwareComputer fileSampling (statistics)Multiplication signTheory of relativityIntegrated development environmentDifferent (Kate Ryan album)State of matterVideo gameElectric generatorNeuroinformatikSound effectEvent horizonSpacetimeSocial classCodeNumbering scheme3 (number)WordWaveMereologyBitSimilarity (geometry)Right angleCondition numberInformationEndliche ModelltheorieVotingSpeciesReplication (computing)Line (geometry)Moment (mathematics)WebsiteForm (programming)Random number generationStrategy gameEmulatorHeuristicOpcodeComputer virusPhysicalismRandomizationPattern languageLink (knot theory)Scripting languageKernel (computing)Normal (geometry)MathematicsSoftwarePolymorphism (materials science)Noise (electronics)Software testing2 (number)Prime idealIdeal (ethics)CryptographySingle-precision floating-point formatFrequencyComputer animation
28:44
Information securityComputer virusData integrityHash functionFunction (mathematics)Feasibility studyMessage passingOpen sourceSound effectCollisionProcess (computing)Regular graphComputer fileExtension (kinesiology)Java appletEquivalence relationElectronic signatureEntire functionMereologyElectric generatorMathematicsInformationNumbering schemeTheoryInformation securityComputer fileINTEGRALHash functionTouch typingMessage passingComponent-based software engineeringProduct (business)Multiplication signSheaf (mathematics)Open sourceCache (computing)Computer virusSound effectProjective planeRegular graphExtension (kinesiology)Java appletMobile appLengthCodeInitial value problemCASE <Informatik>Bit rateSeries (mathematics)Endliche ModelltheorieFunctional (mathematics)Semantics (computer science)StapeldateiDifferent (Kate Ryan album)Social classFactory (trading post)Process (computing)ExistenceForm (programming)Virtual machineField (computer science)QuicksortIntegrated development environmentInterface (computing)Subject indexingStrategy gameInstance (computer science)Level (video gaming)Sampling (statistics)Natural numberWave packetKlassengruppeProcedural programmingNeuroinformatikTask (computing)Computer animationXML
34:14
Convex hullExtension (kinesiology)Entire functionEquivalence relationJava appletElectronic signatureComputer fileContent (media)Function (mathematics)TimestampRandom numberComputer fileCodeFunctional (mathematics)Content (media)RandomizationElectronic signatureReal numberInstallation artValidity (statistics)FlagLine (geometry)Level (video gaming)EmailNumbering schemeSign (mathematics)MathematicsMobile appError messageBitBlock (periodic table)CompilerEqualiser (mathematics)WritingGroup actionSemantics (computer science)FluxState of matterVirtual machineMereologyRight angleoutputFamilySampling (statistics)Product (business)AreaSource codeXMLComputer animation
39:11
Group actionCapability Maturity ModelNatural numberMultiplication signGroup actionProjective planeComputer animationXMLSource codeProgram flowchart
39:59
LoginExecution unitInclusion mapMaxima and minimaConvex hullCurve fittingFunction (mathematics)Parameter (computer programming)Default (computer science)BootingSpacetimeComputer fileInterface (computing)SharewareWeb pageSocial classLoginVolume (thermodynamics)Process (computing)Source codeXML
40:55
Parameter (computer programming)SpacetimeFunction (mathematics)BootingMachine codeInformation managementConvex hullDependent and independent variablesKey (cryptography)Execution unitEmailDenial-of-service attackPunched cardServer (computing)Computer virusPasswordFluid staticsEncryptionStatisticsComputer fileSocial classProcess (computing)Latin squareNamespacePublic-key cryptographyCASE <Informatik>Data structureInformationKey (cryptography)Multiplication signContent (media)MereologyDependent and independent variablesSystem callProjective planeComputer fileEncryptionSocial classEvent-driven programmingCodeComputer virusFunctional (mathematics)Process (computing)Event horizonPasswordFlow separationEmailScripting languageKernel (computing)Group actionGastropod shellType theorySet (mathematics)Square numberRight angleBit rateGame theoryFocus (optics)Line (geometry)Physical systemAxiomSubject indexingSampling (statistics)Medical imagingForm (programming)Amenable groupMessage passingCausalityPlanningPolymorphism (materials science)Source codeXML
46:00
Large eddy simulationConvex hullEncryptionFluid staticsFunction (mathematics)Key (cryptography)Wide area networkSpacetimeParameter (computer programming)BootingCryptographyPasswordMeta elementExecution unitRoyal NavyIndian Remote SensingDependent and independent variablesGame controllerMenu (computing)Photographic mosaicComputer virusEmailPublic-key cryptographyKernel (computing)Web pageComputer fileString (computer science)Social classCASE <Informatik>System callProcess (computing)Event horizonCodeType theoryLattice (order)OracleFunctional (mathematics)Arithmetic meanState of matterExecution unitComputer animationSource code
48:57
Execution unitProjective planeSound effectPublic-key cryptographyScripting languageComputer animation
49:44
Latent class modelConvex hullUniform resource namePivot elementHacker (term)Denial-of-service attackEmailCivil engineeringLibrary (computing)EncryptionLocally compact spaceFunction (mathematics)Content (media)Ext functorQuery languageFluid staticsServer (computing)Group actionLoginMathematicsCryptographyExecution unitMaxima and minimaInformationEmulationOnline chatDialectTerm (mathematics)Menu (computing)Backdoor (computing)Group actionLoginPasswordCASE <Informatik>Cache (computing)Information retrievalCodeComputer fileInformationCategory of beingSlide ruleStress (mechanics)Active contour modelDifferent (Kate Ryan album)Service (economics)File systemComputer animationXML
52:16
Endliche ModelltheoriePublic-key cryptographyElectronic mailing listCodeSource code
53:04
Group actionTheoryPublic-key cryptographyClient (computing)Random number generationServer (computing)Virtual machineProcess (computing)InformationRight angleContext awarenessDifferent (Kate Ryan album)UMLLecture/Conference
55:07
Computer animation
Transcript: English(auto-generated)
00:08
OK, let's start with a talk about creating a crypto-virus for Symfony 2 apps. My name is Rolf Raelle. I come from Spain.
00:22
A little bit about me. I am a software developer at Cybergo. It's a hosting company specializing in PHP hosting. I'm a certified engineer and a Symfony certified developer. I'm now studying a master degree in research in computer technologies.
00:43
I am focusing on cryptography and data compression. I thought it would be interesting to apply those things about cryptography to PHP and especially with Symfony.
01:02
OK, this is something we'll talk about during the talk. We'll see the PHP part files, we'll see a little bit about them. Symfony, even though if you don't know Symfony, I'll explain just a little bit so you can follow the talk.
01:25
And hash functions, cryptography, symfony kernel events, OpenSSL. OK, first we'll define what a crypto-virus is. A crypto-virus is a computer science field that studies how to use cryptography to design malicious software.
01:46
It is closely related to ransomware, which is you get some kind of information or you destroy something and you ask for money or for information to get the information back or to get what you deleted back.
02:03
And also for private information retrieval. From the point of view of a hacker, it's always important to... OK, they want to retrieve some information, but they want to do it safely. So, cryptography can help here.
02:22
And it was a fundamental twist in cryptography. Before that, cryptography was used to protect information, to hide what we don't want to share with the rest of the world. But here, applying cryptography to malicious software was a fundamental twist.
02:47
We'll divide the talk in two main blocks. There will be a quick demo at the end of the talk. First we'll see what is public cryptography, which is very important. We'll see how and why.
03:02
And then some symphony internals. It's also important to know how symphony works internally so we can adapt in some different ways. Some hiding strategies for our vitals, and at the end, protection strategies. How can we protect from this kind of attacks?
03:24
OK, so we're going to see how we're going to create our own creature vitals for fun. Only for fun. This is only for educational purposes. And a warning, this is not a real vitals, it's just a proof of concept.
03:43
Symphony is, I chose symphony because it's what I know. But these same concepts could be applied to some framework, to get PHP, whatever you want, even to play PHP. And we assume that the virus is already in the target computer.
04:02
We don't need to see how to inject that virus in the computer. I'm not a security expert, so this part probably would be done by a security expert. So, a crypto-virus. How are we going to create it?
04:25
So the first step is we're going to have the app server. In the app server we have symphony here, an application written in symphony. And we already have the virus. Then we have another server, which is the server of the hacker.
04:45
So once the virus is here and it's executed, it connects automatically to the hacker server and asks for a public key. We'll see in a couple of minutes, public key cryptography. But the idea is done. We get the public key.
05:02
The hacker server generates a key pair with a private key. So it returns a public key and saves the private key. Then the virus, already with the public key inside, infects the symphony's application.
05:26
And it could be done in many ways, but we are going to use symphony kernel events and the bootstrap.php.kache file. We'll see also how they work.
05:41
And then, once our code is here, we have access to database connection, user upload files, logs, whatever. So we can use that public key to encrypt that information. Once that information is encrypted, sorry, once that information is encrypted using the public key,
06:13
there's no way to decrypt it without the private key, which is in the hacker server.
06:23
So we will need to get that private key, obviously, paying some money. So once we have the private key, we can get back that information. Hacker can use services like Bitcoin to add an extra level of anonymity.
06:48
That will be a ransomware attack and we're going to see also the other kind of attack, the private retrieval information. Using the same code, we have here the infected application.
07:05
Imagine we have a login and password page in symphony. This is done in a kind of special way, so if we know that we are attacking a symphony app, we know how to get that information.
07:22
So once that information is submitted, we can take it here and save it encrypted in a file. So if anyone, the webmaster, knows and sees these kind of files,
07:42
he won't be able to know what is inside because it will be encrypted. Then we will create a backdoor so the hacker server can connect and get the list of users encrypted and using the private key, they will be decrypted.
08:07
We'll see everything in the demo. Now we're going to see the different parts, important parts, to know how the virus works. First, public key cryptography. Who knows how public key cryptography works?
08:28
Lots of people. Public key is also called asymmetric cryptography. It requires two different keys. A public key, so we can share that key with anyone, and a private key.
08:45
We'll use, most of the time, we'll use the public key to encrypt information. There are two ways, we'll see.
09:03
We'll use the public key to encrypt information and the private key to decrypt it. Public key cryptography is based on one-way functions, which are called also trandos. These mathematical functions are really easy to compute in one way and really difficult in the other way.
09:22
We'll see an example now. This is important because it is believed to be difficult. What does that mean? It means that there is no way to do it fast. It doesn't mean that anyone or any organization can have already a method to do it in, to do it fast.
09:46
And some of these one-way functions would be integral factorization, which is used by LSA. We're going to use it. It's pretty logarithm and LDP codes. So, if we have Alice and Bob, and Alice wants to send an image to Bob,
10:06
Alice has her own private key and her own public key, and also Bob. A different private key and a different public key. So, Alice says to Bob, I want to send that image.
10:22
Bob says, okay, I give you my public key. Using that public key, you will be able to encrypt it, so only me will be able to decrypt it later. We can see this like a box with a padlock. Bob is sending a box, an open box, and an open padlock.
10:42
Alice input enters that image in the box, crosses, and crosses the padlock. So, only Bob will be able to open the padlock with the private key. If anyone in the middle gets that information, get just garbage.
11:06
So, this is the factorization problem, okay? For example, if we have p and q, and we want to calculate n, n is a multiplication of p and q. So, even if we use some big numbers for a computer, it's really easy to do it, and really fast.
11:27
In the other way, if we want to know that multiplication, the result, we have the result, and we want to know what two numbers, what use for the multiplication, we will need to factorize, and factorize is really complex for a computer and for a human.
11:47
So, it is slow, and slow means that there is no known way to do it in polynomial time. We'll use OpenSSL for the example, which is a general purpose pictorial key library,
12:07
and because we have an extension, PHP OpenSSL, so we can use it from PHP. We all know what happened with OpenSSL a few months ago.
12:21
So, how can we use OpenSSL from PHP? Imagine we want to create a key pair, okay? A pair of private and public key. We define an array, that is not important now. We say that this is going to be the length of the key and the type, this RSA.
12:44
RSA uses the factorization. With that function, we get a key pair, okay? We get a PHP resource. With other functions, we extract that private key, and then we extract the public key.
13:05
It is not complex, but it requires a few steps, but if you use this in a function, you just want to use the function and get the pair. This is how they look if you already configure Apache, for example, with HTTP support.
13:29
We already know this kind of piece. And then, to encrypt that information, we can use this function, which gets the data to be encrypted,
13:40
the public key, and a reference parameter, so we will get the encrypted information here. Then to decrypt it using another function, we pass the encrypted information. This will be the variable when we will get the encrypted information and the private key.
14:05
So, for our purpose, always encrypt information with the public key and decrypt it with the private key. Is everything clear with the public key cryptography?
14:21
Any questions? Okay. So your virus will use the OpenSSL library, so it adds a dependency, maybe, to the application? The question is that the virus will use OpenSSL, so it is having a requirement for the virus to run.
14:43
Yes, it's a requirement. So, we could do it from PHP manually, but it won't be safe at all. For a virus, it would be a good way.
15:03
So, Symfony. Who have used Symfony before? Who haven't used Symfony before? Symfony is a framework for PHP applications.
15:22
It's quite complex and quite flexible, so you can use the whole framework or you can use only some components. And inside, in every request, there are dispatched a few events. They are called kernel events.
15:42
So, every time a client sends a request, a new object of the request type is created. And then, the kernel.request event is dispatched. There can be one listener or lots of listeners listening to this event, so you can use that information for something.
16:09
Or you can, for example, send a response in that listener and then the execution. Then, when a response object is created, a kernel.response event is dispatched.
16:27
So, we can also use it for whatever. For example, we could use Google Analytics code in that event. It's not the best idea, but we could use it for that.
16:50
Once the response is sent to the browser, it emits an important event, which is kernel.terminate. We are going to use that event for encrypting information, because we are going to encrypt user uploaded files.
17:10
So, this may take time if there are too many files. So, using that event, the client already has the webpage, so we can do it later.
17:24
This is especially useful for, for example, sending emails or post-processing information. Then, in the normal flow, is kernel.controller event dispatched.
17:44
And then, in case we don't return a proper response object in the controller, there is a last opportunity to convert that object, for example, one string, into a proper response object.
18:03
And always, in case there is an exception, an event is dispatched, so we can transfer that exception into a proper response object with extra information, for example. So, we will use this event for encrypting information and this event to get the user and password entered by a client.
18:29
Okay, as we recap, a kernel request, as soon as the request arrives. kernel.controller, once the controller is resolved. kernel.view, in case the controller does not return a response.
18:43
kernel.response. kernel.exception, and terminate, as I said, for expensive for response jobs. And the other part of Symfony that you want to, that you need to know, is the bootstrap.php catchy file.
19:06
This is a file created by, by Symfony. It is created by, it's a composite script, okay, but it is used to improve performance. This is just a huge file with lots of classes and interfaces.
19:23
It's just a copy-paste of those files. Why? Performance. Instead of loading those files separately, we already have here, and we are going to use them for sure, so it's a good idea to have them there.
19:41
If you download the, the standard edition of Symfony, you will see these two commands. So when we do a composite install, or composite update, these commands will be executed and create that bootstrap file.
20:04
Yes? The bootstrap.cache file is generated by PHP or by the composer called? It's... How long, because you talked about the .cache file? Yes, it is generated here. Okay. It's, the command is configured in composer, but it is a bundle of Symfony.
20:27
So we, we describe it there. It was just a question which, if the web server has write permissions to the, to the .cache file,
20:41
if the server is properly configured, it's not necessary, right? You can use, the question is if you, you can use the bootstrap file or not use it. So the question is, if the web server needs write permissions to this .cache file?
21:01
Yes, it needs. But if they are using Symfony, they are probably there, the write permissions. It's not necessary to use it, there are other ways. So we see the third part, hiding the virus.
21:21
Usually antivirus software works in two different ways. The first way is through virus definitions. So virus definition, they are just patterns, so we can look for those patterns in files. Okay? It is fast because it is just to compare a few patterns,
21:44
but it is only useful for non-malware. If there is a no-virus, a new-virus, we won't pass the virus definition, so we won't get it. So the other strategy is to use heuristic.
22:03
Heuristic are also patterns, but you look for suspicious patterns. For example, suspicious TCP IP packets, suspicious kernel events. For example, a virus by definition replicates itself. So this is not a common, this is not common for normal software.
22:23
So this could be a flash, so that could be a virus. Okay, I had to try this, but this works in PHP. You can do a link of the file, so the current script will be deleted.
22:45
So this could be a good way to infect the Symfony app, and once infected, remove the file. We need to inject some code into a booster file, as I said,
23:03
so we can inject it as a normal PHP code, or we can try to make it difficult for a virtual antivirus to detect. So for example, if we want to inject that code, PHP info,
23:21
we can use this technique, there are other techniques, so for example, we encode with base64 five times. Base64 is lossless, so once decoded, we'll get the same information. So we encode it five times, and then we generate a PHP code able to decode it.
23:46
So we'll use eval, which is nice for a virus, for real software. And we'll inject this string, base64decode, five times,
24:03
then code it from here, and then the five parentheses. Then, we can use gzip to compress it, gzip is also lossless,
24:22
so then we will be able to get the original information. So we'll get compressed code. Then, using this, we'll be able to execute the code. We'll see an example also with this later.
24:41
That is nice, but it's just a couple of tricks. So a better idea is to use polymorphic code. Polymorphic code uses a polymorphic enzyme to rotate code. So we pass some code, and we get different code, but that's exactly the same.
25:03
So that makes it really difficult for antivirus software to recognize the code as changes every time. So most of the time, they are forcing to that antivirus software to use emulation to execute that code in a sandbox environment
25:23
to see what it's doing. For example, if we have these five lines of code, all these lines print the same. They print hello world, but they do it in different ways.
25:41
For example, the first one CC, this one also, the fourth one uses the stdout to print it, and the fifth one uses character by character. So all of them print hello world, but using different code.
26:00
Using this, they're making life more difficult for an antivirus. And more important, in PHP, it generates different opcodes. So if you take a look at the generated opcodes, they are all different, so it makes it difficult.
26:25
The goal for a virus would be to create a polymorphic enzyme able to generate different code in its injection, in its infection.
26:47
As you know, this is also really difficult in a computer because it is impossible to generate real random numbers in a computer.
27:04
If you use run or empty run to do cryptography, don't do it. You can see that there are patterns. Even in empty run, there are also patterns. It is better, but not good enough for cryptography.
27:22
So it is always recommended to use physical methods for that. For example, random.org uses atmospheric noise to generate random numbers. And we also, as humans, are not good to generate random numbers.
27:40
So we're going to do a quick test. During five seconds, we're going to think about one number between one and ten. Start. This is real time.
28:01
Most of you probably have thought of the number seven. Because our brain, when it tries to generate a good random number, it says, well, one and ten out because it's the first and the last. Second is too common. And then looks for, okay, it says five in the middle, out.
28:24
And seven is what we consider the weightless one because it's another number, it's prime number, but an ideal single random number generator.
28:40
This is the frequency that it should have. Okay, and the last part is about protecting us. So before the infection, we do what we're used to do. We use such security measures,
29:01
restricted permissions. As you said, disable PHP OpenSSL if you are not going to use it. And something that we can also do is virus inoculation. For example, a virus always have a method
29:23
to see if a given file is already infected or not. So if we know how to check how the virus checks if the file is infected, we can inject that information. For example, in a PHP comment or using the hard compile function and inject that information there.
29:44
So if we know the virus and we want to avoid that attack, can be a good strategy, but only for a given virus. And once the app has been infected, we want to check the integrity to know if it's infected or not.
30:05
So one way to check the, the best way to check the integrity of some code or some information is using hash functions. Hash functions, we are used to use it.
30:20
In everyday, we use SHA-1, for example, MD5 sometimes. And basically, they create fixed length digits, fixed section from data or arbitrary length. They must be easy to compute
30:42
and they must be really, really, really difficult to generate a message with the hash that we want. Really difficult to modify a message without modifying the hash. Really difficult to find two different messages with the same hash.
31:03
This happens because the number of hash numbers is limited, but it must be really difficult. And the basic idea is this. Tiny changes in the source generate big changes in the address.
31:21
So for example, if we are hashing one gigabyte of information and we change just one bit, if the hash function is good enough, it should generate a new hash number with at least 50% of information changed.
31:43
If you like, the cache theory is like this, like the butterfly effect. In initial conditions, little changes in initial conditions lead to big changes at the end.
32:02
So the theory says that the flapping of the wings of a butterfly could cause a twister in the other part of the world in many years. Like when you go to the past and they say,
32:23
don't touch anything. The same idea. Why we don't use MD5 anymore? Because it's not collision resistant. What would be the idea is in the build process,
32:42
when we deploy the project, we can create a hash of the whole project and then check it regularly. For example, using the final component of Symfony, we can get all PHP files, for example,
33:01
and then create a hash of the whole project. So, using that number, we can check it in production from time to time and check if anything changes or not. It could be a nice way,
33:22
but we already have this in PHP, using the par extension. Anyone have used far before? Used. No composer? Okay.
33:40
So, the basic idea is, you encapsulate all the project, even its dependencies, in a single file, in a far file. It's equivalent to Java.js files. And the nice thing for this talk is that far files can contain a signature,
34:01
a section of the included files. So, we are... Sorry.
34:40
Okay, so, can contain a signature of the included files. So, we can have what we did before manually, we can have it automatically. Far files are divided in four blocks. At first, there's a stuff which usually contains some loaded functionality.
35:02
Basically, some code to be able to map between the included files and that PHP code. It always ends with this function, hard compiler. Who knows what that function does?
35:22
Four? That is a real PHP function and what it says is, to the PHP interpreter, to stop. Anything that I put after that, it is not interpreted by PHP. So, we can use it, for example,
35:42
for install script, for example. Then, we have a manifest. This is no longer PHP valid code because we use this function. The manifest, basically, has the name of the included file names,
36:04
some checking, the timestamp, size, some binary flags. Then, the actual contents. We'll have here PHP code, our dependencies,
36:21
and at the end, a signature. So, we can have a signature, and then the files are one, two, and fifty-six, and five-twelve. So, I created a, there's only a missing line. I created a really simple far file.
36:42
So, we, you can see here, we open PHP, we execute map file, so we can map between, we can access the included files, and echo hello world. And then, I compile it.
37:00
This is the start. Then, there's the manifest. This is all of this. This is basically some flags. This is also a manifest. This is the file I included. I included a file called one dot txt.
37:23
Then, the file contents. So, the file has some random text inside. And then, the signature. This is our SHA-1 signature. The signature flag,
37:40
which indicates the kind of signature we use. And a mailing number indicating that there is a sign up. So, what happens if we are really small, really smart, and say, well, we're going to change hello world by hello there. So, our virus, for example,
38:01
will do something like that, change code. If we try to execute that part, we get an error. An error that has a broken signature. So, automatically, PHP is checking that for us.
38:20
I hope what happens if we are even more smart, and we change that little bit that says if there is a signature or not. If we try to execute it again, we can do it, before it doesn't have a signature. Is it mandatory for far file to have a signature?
38:40
No, it is not. But by default, in the PHP.ini file, we have this line. So, far files are required to have a signature. So, packaging a whole app into a far file
39:02
could be a good idea to avoid this kind of a problem. And then, yes? If the attacker can write a far file, he also can recalculate the signature and write it too. Yes, that could be, if you are even more, more, more smart.
39:23
I tried to do it. I couldn't. But I need to spend more time on this. So, let's see in action.
39:41
Is there any question? Before seeing the code? No? I downloaded a Symfony project. In Symfony, there are a few demos.
40:02
And I am using that demo. In that demo, you have a simple page like this and a simple login for here.
40:37
Can you see it? At the end? Yes?
40:41
Okay. This is the bootstrap file. As you see, it is a huge file containing a copy paste of common Symfony classes and interfaces. It uses the special way of using name spaces.
41:04
You can have several name spaces in the same file. I'm using this notation. And what we are going to do is inject some code here. As I said,
41:23
there is a server, the hack server, which will provide the public key. So this is the script. As we did before, this is the only thing that changes.
41:42
It generates a shell one of the public key. This is only to have a kind of ID. So if that person pays the money, we can, from that key, get the private key. We will save the private key here.
42:03
And type of contents. And the response will be an array containing the ID and the public key. So we are saving the public key and storing the private key. In case it pays,
42:23
we return the private key saved here. Okay. The Symfony project has a known structure. We could use any other framework,
42:42
but as we know already, Symfony. And we know that the upload file is here. So we have a txt file containing hello world and an image. Imagine that this
43:01
was uploaded by final users. So we are going to encrypt it and in case they don't have a backup, they lose that information if they don't pay back. And this is the code of the virus.
43:22
No clean code here. Basically, this will be a super polymorphic enzyme. We are going to create a class because our virus is subject-oriented.
43:42
We are going to create a different class every time. So the name of the class would be v1, v10,000, v50,000. And we generate here the code.
44:02
Basically, we have an encrypt function. We have a decrypt function, handle action, which depending on the request will do anything.
44:22
And now the important part will be here. We are getting the contents of the booster file. Once we get the contents, we want to inject some code to be in the middle of the symphony request. So what we are going to do is
44:43
to look for this code. This is the code of the event dispatcher. And what we will do will be to maintain that code, but in front of this code, inject a call to our virus,
45:01
a call to that process method of our virus, which is static. And we will pass the event. So then, depending on the event, for example, the request event, we will do the struct user and password
45:21
in the response. Just for testing, we will do, we will modify the response, adding an extra header containing the symphony you have in fact. And the kernel terminate will do the encryption. It will read the uploads folder
45:43
and encrypt all files. Let's see in action. This one is commented, so I don't want to lose the virus. Okay.
46:10
So it will execute the virus, automatically connects to the header server, gets the public key.
46:21
The public key is then injected inside the virus. So if we open the Mustra file again, we have this code now. This code is only one big line, so it's more difficult to detect.
46:44
This code is doing all of this. This code contains this class, the class we will need in everything. And we also change some function calls.
47:04
We look for this. For example, here, the kernel terminate event. The code, the normal code is here,
47:21
but now it is injected. This code. It's calling to the virus the process method with the type of event and event itself.
47:47
So, if it does it in every request because kernel terminate is executed in every request. So it will refresh this page.
48:11
If we see the feeders,
48:21
here is the extra header we have. And if we see the files, we know that they are encrypted now. So if we find this and it's a project, we have a problem. I added this string at the beginning
48:41
so the file is not encrypted twice. And then to, in case we fail, we can execute.
49:05
We have a script, we see now, and revert. So, what we are doing now is sending the private key to the project.
49:24
Demo effect.
49:44
Okay, it is encrypted now, and it is decrypted.
50:02
We are using a backdoor to do this. So, how the backdoor does, works. If you see the code, the code is available online, so you can take a look later.
50:28
Here, in every request, it gets some action. So, in case the action is to revert that information, also it does the same, but in this case, reverting.
50:43
Okay, and the last part, that would be the private information retrieval. We have this, a simple login and password. So, we say, user FrostCon, password 123465.
51:04
It is not valid, but could be valid. And we can see, in the cache file, there's a new folder called users.
51:21
I am saving them there. And there's a file, okay. We open the file, it's encrypted. So, if anyone finds out this file, well, it could be deleted, but they have no way
51:41
to accuse us for something. Okay, because they don't know what it is. They know that they are probably users, because I named that way the folder, but I could use any name. Okay, it would say FrostCon 2-1-2-3.
52:04
We have two different files. And, just in the back door, we can get the users.
52:23
It is downloading the user, the list of users, and using the private key to decrypt it.
52:45
Okay, they are there. FrostCon 2-1-2-3 and FrostCon 1-2-3-4-5-6. Okay, and that's all.
53:01
There's the code of the virus. You can take a look and play with it, and send pull requests to make it even more stronger. Okay, thank you. Any questions?
53:30
On the server side, on the attack system, they use the private key, then you throw it away. Sorry, no, I'm sorry. Then you encrypt the private key on the client system,
53:40
your private key, and then for getting, I'm not, he has to send you the encrypted private key, and you're the one who encrypted it. You don't have to go to an outside server. It's only in the ransom process. Yes, that's a way that you need that the client machine allows to do that.
54:03
It's driving an extra dependency. That machine must have appropriate server random number generator, but yes, yes.
54:26
It's much better training, so you have to just go back to the last backup, and that's it. But if you make the data dirty over time, it's really difficult.
54:43
It is nice to think from the dark side sometimes. You learnt a lot. Any other questions? Thank you.