WEBVTT
Kind: captions
Language: en

00:00:00.080 --> 00:00:06.919 align:start position:19%
this was the original form of the file
all on one line and heavily obfuscated

00:00:04.640 --> 00:00:10.360 align:start position:19%
and this is the deop fiscated portion
looks so much better looks really

00:00:11.120 --> 00:00:19.800 align:start position:19%
beautiful
[Music]

00:00:17.720 --> 00:00:23.439 align:start position:19%
esing hi everyone thanks for watching
Lori wired and in this video I'm going

00:00:21.600 --> 00:00:27.800 align:start position:19%
to be manually reverse engineering and
deating OB fiscated JavaScript code now

00:00:26.599 --> 00:00:32.200 align:start position:19%
the code we're going to be looking at
today belongs to the async rat remote

00:00:30.080 --> 00:00:36.559 align:start position:19%
access tool software and this software
is really commonly abused by malware

00:00:34.079 --> 00:00:41.160 align:start position:19%
authors to perform remote commands or
even exfiltrate data from a victim's

00:00:38.719 --> 00:00:45.600 align:start position:19%
machine JavaScript code is really
commonly very heavily OB fiscated making

00:00:44.079 --> 00:00:49.600 align:start position:19%
it much more difficult to reverse
engineer and this is because if you

00:00:47.440 --> 00:00:53.320 align:start position:19%
don't have aisc inside of JavaScript
code it's really simple to be able to

00:00:51.199 --> 00:00:57.160 align:start position:19%
take a look at the script and understand
the full capabilities of what it's able

00:00:55.199 --> 00:01:01.039 align:start position:19%
to do if you're reverse engineering on
fiscated JavaScript code the best thing

00:00:59.120 --> 00:01:05.760 align:start position:19%
to do is go through to rename all of the
variables rearrange the functions and

00:01:03.719 --> 00:01:09.360 align:start position:19%
try to create an approximated view of
what the script looked like to the

00:01:07.320 --> 00:01:13.200 align:start position:19%
original Mau author before they added
the obfuscation so that you can

00:01:11.240 --> 00:01:16.320 align:start position:19%
understand the full capabilities of this
script so let's get right into it and

00:01:14.960 --> 00:01:20.159 align:start position:19%
let's see what that looks like I'm
already on my maare analysis machine and

00:01:18.320 --> 00:01:24.479 align:start position:19%
this is a dedicated machine that is
secure and I don't mind performing

00:01:22.000 --> 00:01:28.320 align:start position:19%
Dynamic analysis or infecting I'm not
going to be directly performing Dynamic

00:01:26.360 --> 00:01:32.439 align:start position:19%
analysis on this sample so I'm going to
go through this statically and just

00:01:30.200 --> 00:01:36.680 align:start position:19%
dynamically analyze certain portions of
this as I'm doing the deop fisc and

00:01:34.759 --> 00:01:40.040 align:start position:19%
potentially decoding strings inside of
the

00:01:37.560 --> 00:01:44.159 align:start position:19%
sample so I already have my sample
downloaded and I will share the shot 256

00:01:42.280 --> 00:01:48.040 align:start position:19%
hash in the comment section of this
video but what I want to do first is I

00:01:46.079 --> 00:01:52.680 align:start position:19%
just want to open this script file in
any text editor and take a look at the

00:01:50.280 --> 00:01:57.880 align:start position:19%
contents and see what's inside so I'm
going to open up notepad plus plus let's

00:01:55.159 --> 00:02:01.680 align:start position:19%
take our sample and let's just drop this
inside now right off the bat you can

00:02:00.039 --> 00:02:05.640 align:start position:19%
tell this has a lot of obfuscation
inside of it probably the most obvious

00:02:03.799 --> 00:02:10.119 align:start position:19%
thing that you'll see is that all of
this code is performed on a single line

00:02:08.399 --> 00:02:14.200 align:start position:19%
this doesn't change the functionality of
the sample it will still run just fine

00:02:12.440 --> 00:02:18.160 align:start position:19%
it just makes it a lot harder to
manually reverse engineer this portion

00:02:16.080 --> 00:02:22.560 align:start position:19%
of the file Additionally you might
notice these weird hexadecimal looking

00:02:20.280 --> 00:02:26.760 align:start position:19%
numbers these are actually valid
variable names they're are prefixed by

00:02:25.080 --> 00:02:31.239 align:start position:19%
this underscore and then all of the
characters inside of here do make

00:02:28.720 --> 00:02:36.040 align:start position:19%
acceptable identifier names so we can
rename all of these to be more human

00:02:33.840 --> 00:02:39.680 align:start position:19%
inuitive names as we're performing this
deobfuscation process now the first

00:02:38.120 --> 00:02:44.120 align:start position:19%
thing that I like to do when I'm reverse
engineering opis JavaScript is try to

00:02:41.920 --> 00:02:48.400 align:start position:19%
fix some of the new lines and spacing so
that we don't have all of our code

00:02:45.680 --> 00:02:52.840 align:start position:19%
jumbled into one really ugly line now
there's a plugin that I really like

00:02:49.959 --> 00:02:58.120 align:start position:19%
called JS tool inside of notepad++ so
I'm just going to do plugins JS tool and

00:02:55.720 --> 00:03:02.200 align:start position:19%
then I can call JS format and all this
is doing is going through and fixing all

00:03:00.360 --> 00:03:06.000 align:start position:19%
of the spacing and new lines to
correspond to what would be commonly

00:03:04.040 --> 00:03:09.200 align:start position:19%
expected inside of the JavaScript
language now I want to take kind of a

00:03:07.599 --> 00:03:13.680 align:start position:19%
cursory look and see what's happening
inside of here and how much code we're

00:03:11.480 --> 00:03:18.280 align:start position:19%
dealing with it looks like this is
pretty heavily OB fiscated we don't have

00:03:16.000 --> 00:03:22.680 align:start position:19%
a lot of variable names that provide any
indication of what is the potential

00:03:20.200 --> 00:03:27.720 align:start position:19%
functionality of this but I do see some
interesting keywords inside here one

00:03:25.000 --> 00:03:32.080 align:start position:19%
thing of note is this active X object
this allows the JavaScript code to

00:03:29.799 --> 00:03:36.200 align:start position:19%
interface with the underlying system so
this is really good interesting portions

00:03:34.159 --> 00:03:39.439 align:start position:19%
and really commonly abused by malware
authors so we definitely want to keep

00:03:37.920 --> 00:03:43.720 align:start position:19%
that in mind and take a look at that a
little bit later I'm going to do a

00:03:41.760 --> 00:03:50.000 align:start position:19%
little bit of a cursory glance try to
find any other strings this looks very

00:03:47.200 --> 00:03:54.680 align:start position:19%
interesting just immediately this looks
like a sequence of strings inside of an

00:03:52.400 --> 00:04:00.200 align:start position:19%
array that have potentially very
interesting data also they have little

00:03:57.400 --> 00:04:04.799 align:start position:19%
obfuscation techniques inside this is
just performing the heximal version of

00:04:02.680 --> 00:04:08.799 align:start position:19%
this character but this is actually a
regular asy character and if you print

00:04:07.000 --> 00:04:12.200 align:start position:19%
out this string it should look like
something you would expect going on to

00:04:10.519 --> 00:04:17.600 align:start position:19%
the rest of the array it doesn't look
like it's in any particular order

00:04:15.079 --> 00:04:21.720 align:start position:19%
meaning that this might get reordered or
maybe there will be functions inside of

00:04:19.799 --> 00:04:25.280 align:start position:19%
here that look at particular indices
inside of this but this definitely looks

00:04:24.120 --> 00:04:29.160 align:start position:19%
like it's probably going to be
referenced later and has some really

00:04:26.880 --> 00:04:34.440 align:start position:19%
useful data inside of here so we'll keep
an eye on that as as well going back up

00:04:32.280 --> 00:04:38.440 align:start position:19%
let's see what else we have inside of
here that's pretty much it for all of

00:04:36.560 --> 00:04:42.080 align:start position:19%
the human readable terms that are in
here by default we also have this parse

00:04:40.199 --> 00:04:45.759 align:start position:19%
int this is just a keyword inside of the
JavaScript language that's going to

00:04:43.639 --> 00:04:51.080 align:start position:19%
allow the program to parse an integer
from the provided argument but let's go

00:04:48.800 --> 00:04:56.440 align:start position:19%
through and try to find where the
portion of the code is that begins

00:04:53.240 --> 00:05:00.800 align:start position:19%
execution first now the first thing to
note is we have this VAR up here that's

00:04:59.120 --> 00:05:05.560 align:start position:19%
going to be the first portion that's
executed and we have a couple function

00:05:03.400 --> 00:05:09.160 align:start position:19%
definitions now one interesting thing to
note about this particular function

00:05:07.320 --> 00:05:12.919 align:start position:19%
definition is that this is something
called an immediately invoked function

00:05:11.039 --> 00:05:17.680 align:start position:19%
expression that means it's going to be
immediately executed as it's declared

00:05:15.759 --> 00:05:22.680 align:start position:19%
you'll notice that this is inside of
parentheses and we have other

00:05:19.400 --> 00:05:27.039 align:start position:19%
parentheses over here this is the actual
argument passed to the function so this

00:05:24.800 --> 00:05:31.840 align:start position:19%
is going to be argument one and then
this whole expression is going to be

00:05:28.319 --> 00:05:36.280 align:start position:19%
argument two passed to this function
this is defining parameter 1 and

00:05:34.080 --> 00:05:40.360 align:start position:19%
parameter 2 this is going to execute
immediately so taking a look at the

00:05:38.199 --> 00:05:44.440 align:start position:19%
script the first line of execution is
going to start inside of this function

00:05:43.000 --> 00:05:47.960 align:start position:19%
and then we're going to continue on
inside of this Tri catch statement where

00:05:46.560 --> 00:05:53.199 align:start position:19%
we have a couple other function
definitions it looks like we've got one

00:05:51.000 --> 00:05:57.440 align:start position:19%
defined and then immediately invoked
right after that as well and then this

00:05:55.080 --> 00:06:01.160 align:start position:19%
is simply a regular function so I'm
going to first of all move around my

00:05:59.160 --> 00:06:05.919 align:start position:19%
functions a little bit to make the flow
of execution just a little bit clearer

00:06:04.000 --> 00:06:09.240 align:start position:19%
now before I move around these functions
I'm going to quickly make a copy of this

00:06:07.400 --> 00:06:12.880 align:start position:19%
code because it's very easy to break
stuff as you're trying to deobfuscate

00:06:11.120 --> 00:06:17.039 align:start position:19%
your script code and you might want to
reference that original code later so

00:06:15.039 --> 00:06:22.039 align:start position:19%
I'm just going to do copy and let's move
this into a new file and let's set our

00:06:19.800 --> 00:06:26.440 align:start position:19%
language real quick
to JavaScript so we can get some nice

00:06:24.479 --> 00:06:30.639 align:start position:19%
syntax highlighting now I'm going to
begin my modification process so first

00:06:29.280 --> 00:06:34.599 align:start position:19%
of all I'm going to move around these
functions so I can see where the

00:06:32.479 --> 00:06:39.400 align:start position:19%
execution is starting and where the
function declarations are so let me get

00:06:37.039 --> 00:06:44.479 align:start position:19%
rid of this and let's just move this up
here I'm going to move my regular

00:06:42.440 --> 00:06:48.840 align:start position:19%
functions not the immediately invoked
ones right next to each other now we

00:06:46.720 --> 00:06:52.400 align:start position:19%
have the flow of control a little bit
clearer inside of here these are going

00:06:50.280 --> 00:06:56.960 align:start position:19%
to be functions that are referenced and
then our actual code execution is going

00:06:54.160 --> 00:07:00.680 align:start position:19%
to start pretty much down here the next
thing I want to do is I kind of want to

00:06:58.280 --> 00:07:04.960 align:start position:19%
start from the top and de alisca a few
of these variable names because they're

00:07:02.919 --> 00:07:09.039 align:start position:19%
very frustrating to read and I want to
make this a lot clearer and a lot easier

00:07:07.240 --> 00:07:14.240 align:start position:19%
to process so I'm going to start with
this variable up here this is another

00:07:12.280 --> 00:07:19.639 align:start position:19%
obfuscation technique you can see we're
setting a variable equal to a function

00:07:17.080 --> 00:07:24.840 align:start position:19%
name this function declared right here
this is an anonymous function call so we

00:07:22.240 --> 00:07:29.240 align:start position:19%
can call this variable just the same you
see it's being invoked down here and

00:07:27.240 --> 00:07:32.800 align:start position:19%
then this is going to invoke this
function function so keep in mind when

00:07:31.199 --> 00:07:37.520 align:start position:19%
you're reverse engineering JavaScript
code this is a really common kind of

00:07:34.599 --> 00:07:40.879 align:start position:19%
obis technique to look out for now what
I'm going to do to make this a little

00:07:38.800 --> 00:07:45.840 align:start position:19%
bit more readable is I'm going to take
this variable name and I'm simply going

00:07:43.120 --> 00:07:51.840 align:start position:19%
to rename it to this to make it clear
what I'm actually invoking up here so

00:07:48.280 --> 00:07:57.280 align:start position:19%
I'm going to do copy then
crlf and let's just do find and replace

00:07:55.599 --> 00:08:00.800 align:start position:19%
and I'm going to find all occurrences of
that variable name I'm just going to

00:07:58.800 --> 00:08:04.680 align:start position:19%
rename to them to the method
name so let's do that so that's a little

00:08:03.159 --> 00:08:08.319 align:start position:19%
bit clearer and now I'm going to remove
this variable entirely so that I know

00:08:06.840 --> 00:08:10.960 align:start position:19%
what code I'm going to be calling now
the next thing I want to do is take a

00:08:09.479 --> 00:08:15.319 align:start position:19%
look at the contents of this function
and try to clarify the flow of execution

00:08:13.199 --> 00:08:19.680 align:start position:19%
inside of here we have this variable
being set to the return value of this

00:08:17.520 --> 00:08:23.800 align:start position:19%
function and this function was the one
setting all of the interesting strings

00:08:21.599 --> 00:08:28.319 align:start position:19%
that kind of looked like sub commands or
subprocesses inside of here so I'm going

00:08:26.319 --> 00:08:32.080 align:start position:19%
to take a look at this function and
rename some of the variables to make it

00:08:30.000 --> 00:08:36.479 align:start position:19%
a little bit clearer first of all I'm
just going to contrl f and rename all of

00:08:34.919 --> 00:08:40.560 align:start position:19%
these to something a little bit more
appropriate and human readable so I'm

00:08:38.519 --> 00:08:43.719 align:start position:19%
going to do find and replace and I'm
going to call this array so I know what

00:08:41.880 --> 00:08:49.279 align:start position:19%
data type it is and I'm going to replace
all occurrences of this and taking a

00:08:46.640 --> 00:08:53.800 align:start position:19%
look at this this is another obfuscation
technique you see that this function is

00:08:51.680 --> 00:08:59.440 align:start position:19%
defined up here but then it's being
redefined to return this VAR command

00:08:56.440 --> 00:09:04.720 align:start position:19%
string array up here so we can just simp
simply get rid of this redefin and have

00:09:02.440 --> 00:09:08.920 align:start position:19%
this by default return this command
string so I'm going to get rid of this

00:09:06.640 --> 00:09:13.480 align:start position:19%
invocation since this is just invoking
the redefined version and let's make

00:09:11.240 --> 00:09:18.920 align:start position:19%
this a little bit
clearer so I'm going to get rid of

00:09:16.040 --> 00:09:23.040 align:start position:19%
that so all we're doing now is simply
defining this array and then returning

00:09:21.160 --> 00:09:26.800 align:start position:19%
it and then that's the actual
functionality of this function so I'm

00:09:25.399 --> 00:09:31.360 align:start position:19%
going to rename this function now that
we know what it is doing I'm going to

00:09:28.800 --> 00:09:31.360 align:start position:19%
call this

00:09:31.399 --> 00:09:38.200 align:start position:19%
malware MW for malware and then let's
say

00:09:35.560 --> 00:09:42.800 align:start position:19%
return command
string

00:09:40.320 --> 00:09:46.320 align:start position:19%
array and we'll rename all occurrences
of that for

00:09:44.360 --> 00:09:50.640 align:start position:19%
clarity now if we look at our function
up here this is calling that function

00:09:48.920 --> 00:09:54.560 align:start position:19%
and storing the return value which is
going to be this array inside of this

00:09:52.640 --> 00:10:00.279 align:start position:19%
variable so I'm going to rename this
variable now for clarity let's call

00:09:58.079 --> 00:10:07.360 align:start position:19%
this V
and we'll just say the same thing

00:10:03.000 --> 00:10:11.480 align:start position:19%
command string array we'll say copy just
to clarify and differentiate between the

00:10:09.560 --> 00:10:16.320 align:start position:19%
different portions of this variable used
throughout the code I'm going to replace

00:10:14.040 --> 00:10:22.000 align:start position:19%
that now this is getting a little bit
clearer same thing we have this kind of

00:10:18.839 --> 00:10:26.959 align:start position:19%
weird redefinition of a function inside
of a function let me change some of this

00:10:24.839 --> 00:10:31.399 align:start position:19%
to make the actual execution a little
bit more intuitive this read up

00:10:29.360 --> 00:10:35.120 align:start position:19%
definition this is the function name but
we're setting it equal to a new function

00:10:33.399 --> 00:10:39.120 align:start position:19%
which is going to be this and then
immediately invoking that function again

00:10:37.079 --> 00:10:42.760 align:start position:19%
with the new Behavior now I'm going to
do the same thing that I did down here

00:10:40.800 --> 00:10:47.480 align:start position:19%
and kind of move around the variables
and contents of this to make it clearer

00:10:45.440 --> 00:10:51.959 align:start position:19%
I'm going to get rid of
this we have new function parameter

00:10:50.120 --> 00:10:55.560 align:start position:19%
names these are just the regular
parameter names even though they look a

00:10:53.519 --> 00:11:00.639 align:start position:19%
little bit funky now I'm going to take
these and change those here since this

00:10:57.880 --> 00:11:05.000 align:start position:19%
is going to be the new definition used
inside let's do that and then let's get

00:11:03.399 --> 00:11:09.720 align:start position:19%
rid of this return and the second
invocation of the

00:11:07.200 --> 00:11:14.399 align:start position:19%
method we'll just remove that fix our
spacing a little bit get rid of that

00:11:14.800 --> 00:11:21.079 align:start position:19%
invocation and this is a much clearer
view of what the method is doing now we

00:11:19.320 --> 00:11:25.839 align:start position:19%
have this variable this is just one of
the parameters and it looks like it's

00:11:23.639 --> 00:11:29.839 align:start position:19%
setting it equal to itself minus some
number and it's really easy to make this

00:11:28.079 --> 00:11:33.200 align:start position:19%
number a little bit more human readable
we're just going to open up our

00:11:30.839 --> 00:11:38.600 align:start position:19%
developer tools inside of our edge
browser I'm going to take this

00:11:35.760 --> 00:11:45.560 align:start position:19%
code and this just evaluates to probably
some integer number I'm going to open up

00:11:41.519 --> 00:11:45.560 align:start position:19%
my developer tools see we can just do

00:11:46.920 --> 00:11:53.200 align:start position:19%
console.log hello
world and it just prints it to the

00:11:51.600 --> 00:11:56.760 align:start position:19%
console so same thing we can do with
this integer value to see what the

00:11:54.920 --> 00:12:02.120 align:start position:19%
integer is and make this a little less
funky looking and do console.log

00:11:59.760 --> 00:12:05.880 align:start position:19%
log and we'll just paste in that integer
value and it looks like it's just the

00:12:04.040 --> 00:12:11.279 align:start position:19%
integer
477 so I'm going to replace that inside

00:12:08.639 --> 00:12:16.440 align:start position:19%
of here to make this a little bit
easier now we're looking at the command

00:12:13.639 --> 00:12:20.800 align:start position:19%
string array and this is passing in this
variable and this to me just looks like

00:12:18.240 --> 00:12:25.800 align:start position:19%
an index value so it looks like we are
finding the array string at a particular

00:12:23.639 --> 00:12:29.880 align:start position:19%
index and then returning that let me
just rename my variables accordingly to

00:12:27.480 --> 00:12:37.320 align:start position:19%
demonstrate this functionality
I'm going to call this index so I'll say

00:12:33.560 --> 00:12:40.800 align:start position:19%
VAR index we'll replace that make it a
little bit

00:12:38.199 --> 00:12:46.480 align:start position:19%
readable does not look like our second
parameter is used and then if we see

00:12:43.480 --> 00:12:49.880 align:start position:19%
other invocations of this it does look
like they're only passing in one

00:12:47.800 --> 00:12:53.720 align:start position:19%
parameter that is allowed in JavaScript
as weird as it is I'm just going to

00:12:51.639 --> 00:13:00.120 align:start position:19%
remove this for clarity since it doesn't
seem to be used at all and I'm going to

00:12:56.120 --> 00:13:03.279 align:start position:19%
rename this getting our index
and we'll rename this variable we'll

00:13:01.600 --> 00:13:08.199 align:start position:19%
just call this
far

00:13:05.000 --> 00:13:13.079 align:start position:19%
string to
return and there we go we have two

00:13:11.360 --> 00:13:17.720 align:start position:19%
functions that have been basically
entirely deop fiscated last thing I want

00:13:15.360 --> 00:13:21.519 align:start position:19%
to do is rename this function so that we
know what we're calling I'm going to

00:13:19.839 --> 00:13:30.079 align:start position:19%
call this
malware get command string at index and

00:13:28.560 --> 00:13:34.240 align:start position:19%
this is getting really long but that's
okay because it's super descriptive of

00:13:31.760 --> 00:13:38.199 align:start position:19%
what the function is doing and we'll
just replace all occurrences of those

00:13:36.639 --> 00:13:42.000 align:start position:19%
now these two functions are perfectly
deop facated so we can move on to the

00:13:40.040 --> 00:13:45.680 align:start position:19%
next portion of code which is what is
going to be executing on the system

00:13:44.320 --> 00:13:49.880 align:start position:19%
initially let's move on to our
immediately invoked function expression

00:13:47.600 --> 00:13:54.240 align:start position:19%
down here and we have a lot of these
similar obfuscation techniques now we

00:13:51.759 --> 00:13:59.199 align:start position:19%
know we've seen these before these OBC
variable names as well as this variable

00:13:56.320 --> 00:14:04.040 align:start position:19%
getting set to point to a function so
that we just invoke the function as this

00:14:01.600 --> 00:14:09.800 align:start position:19%
indirect reference to that function let
me get rid of that to make this flow a

00:14:06.240 --> 00:14:13.920 align:start position:19%
little clearer I'm going to contrl f
I'll copy this

00:14:11.639 --> 00:14:16.759 align:start position:19%
name we'll just replace all occurrences
of that so we know what function we're

00:14:15.480 --> 00:14:21.680 align:start position:19%
trying to
invoke and now I can get rid of this

00:14:19.040 --> 00:14:26.279 align:start position:19%
variable as
well there we go now be careful don't

00:14:24.759 --> 00:14:30.320 align:start position:19%
accidentally think something is a
reference to a function when it's just

00:14:27.920 --> 00:14:33.759 align:start position:19%
invoking the function if it has these
parameters that means the function is

00:14:32.000 --> 00:14:38.519 align:start position:19%
getting invoked and you're storing the
return value inside of this variable

00:14:36.120 --> 00:14:43.079 align:start position:19%
instead let me look at this interesting
Loop right here it looks like we're

00:14:40.600 --> 00:14:47.920 align:start position:19%
performing some sort of array operations
to remove and shift around the elements

00:14:45.600 --> 00:14:51.959 align:start position:19%
inside of the array my guess is that
we're going to be referencing the values

00:14:49.680 --> 00:14:56.240 align:start position:19%
in this so that we can get a more clear
view of the commands that are trying to

00:14:53.720 --> 00:14:59.560 align:start position:19%
be executed on the machine so I'm
guessing this is going to be rearranging

00:14:57.920 --> 00:15:05.639 align:start position:19%
that array into something a little bit
more sensical here let me go through and

00:15:02.040 --> 00:15:10.079 align:start position:19%
make sure my thought process is correct
I'm going to look at this looks like

00:15:06.839 --> 00:15:16.720 align:start position:19%
we're parsing some integer values let me
rename this so we can see what function

00:15:12.440 --> 00:15:22.759 align:start position:19%
we are invoking this is the parameter of
this which is a little bit funky because

00:15:19.079 --> 00:15:27.759 align:start position:19%
we are passing in a function to this so
this really is just a function and I'm

00:15:25.199 --> 00:15:31.800 align:start position:19%
going to rename this for clarity as well
I'm going to copy this and let's rename

00:15:29.680 --> 00:15:36.800 align:start position:19%
that parameter so remember this is
parameter 1 which corresponds to this

00:15:35.160 --> 00:15:42.240 align:start position:19%
this is the second argument which
corresponds to this parameter value

00:15:39.279 --> 00:15:46.480 align:start position:19%
right here so I'm going to contrl f
we'll replace that with the actual

00:15:44.319 --> 00:15:51.920 align:start position:19%
function that's getting passed in and
I'm going to call this VAR so we know

00:15:48.319 --> 00:15:56.600 align:start position:19%
this is a variable and not the function
itself okay here we go that looks good

00:15:55.160 --> 00:16:02.279 align:start position:19%
and then this is going to be the return
value so for the command string array

00:16:00.000 --> 00:16:05.600 align:start position:19%
this is returning our string of commands
inside of an array and I'm going to

00:16:03.959 --> 00:16:08.720 align:start position:19%
rename this variable
accordingly and I'm just going to call

00:16:07.560 --> 00:16:15.959 align:start position:19%
this
VAR command string array very

00:16:11.720 --> 00:16:20.639 align:start position:19%
easy we'll call this copy two just for
clarity there we go and it does indeed

00:16:18.759 --> 00:16:24.279 align:start position:19%
look like we're performing some array
operations this just looks like a little

00:16:22.480 --> 00:16:31.360 align:start position:19%
bit of math kind of an obfuscation
technique to decide what array IND

00:16:28.360 --> 00:16:36.399 align:start position:19%
indices to remove and move around but
we're doing the same thing regardless of

00:16:33.880 --> 00:16:41.040 align:start position:19%
whether we enter this if else or if we
have an acception and enter that catch

00:16:38.839 --> 00:16:44.759 align:start position:19%
statement from the tri catch this is
effectively doing the same thing inside

00:16:42.759 --> 00:16:48.920 align:start position:19%
of the loop so I'm going to stop my deop
isation process right there and just

00:16:46.880 --> 00:16:52.319 align:start position:19%
kind of allow this function to be so I'm
going to use a little bit of dynamic

00:16:50.079 --> 00:16:57.120 align:start position:19%
analysis to let this rearrange our
elements for us the next thing I want to

00:16:54.839 --> 00:17:00.440 align:start position:19%
do is look at the main work which is
inside of our TR catch statement and

00:16:59.040 --> 00:17:04.959 align:start position:19%
this is going to be the final code that
executes we have our functions up here

00:17:02.800 --> 00:17:09.039 align:start position:19%
which are setting up an array of string
values we have this immediately invoked

00:17:07.480 --> 00:17:13.720 align:start position:19%
function over here that's going to be
rearranging our array values but then I

00:17:11.679 --> 00:17:18.520 align:start position:19%
think the actual portion of malicious
code is probably going to ur inside of

00:17:16.039 --> 00:17:22.520 align:start position:19%
this Tri catch block down here the next
process of this gets pretty manual and

00:17:20.480 --> 00:17:27.559 align:start position:19%
repetitive it looks like we have a lot
of calls to these functions to try and

00:17:25.640 --> 00:17:32.160 align:start position:19%
add all of these different string values
inside this is just another variable

00:17:29.960 --> 00:17:35.520 align:start position:19%
that's pointing to our Command string
function that's going to be returning

00:17:33.760 --> 00:17:39.160 align:start position:19%
that command string and then we're
setting all of these values inside of

00:17:37.440 --> 00:17:42.840 align:start position:19%
here now what I'm going to do is I'm
going to go through and replace all of

00:17:41.120 --> 00:17:47.360 align:start position:19%
these function calls with their
corresponding actual string values so

00:17:45.400 --> 00:17:51.440 align:start position:19%
that we can make this code really clear
of How It's executing and what strings

00:17:49.520 --> 00:17:55.039 align:start position:19%
is trying to reference let me rename a
couple of these variables before we go

00:17:53.160 --> 00:17:59.880 align:start position:19%
through and replace all of the strings
inside of this method now let's take our

00:17:57.880 --> 00:18:03.280 align:start position:19%
active X object that's the one I talked
about a little bit earlier that allows

00:18:01.600 --> 00:18:08.039 align:start position:19%
this application to interface with the
underlying system and this is getting

00:18:05.480 --> 00:18:12.559 align:start position:19%
command strings at a certain index so
it's calling this function that's

00:18:10.039 --> 00:18:16.120 align:start position:19%
defined up here now I want to get the
actual value of this so I'm going to

00:18:14.360 --> 00:18:21.120 align:start position:19%
execute this inside of my developer
tools let me first rename this variable

00:18:18.520 --> 00:18:28.360 align:start position:19%
just for clarity going to find this and
let's call this VAR active X object so

00:18:26.880 --> 00:18:33.600 align:start position:19%
we can see where it's referenced later
on and side of the code and now I want

00:18:30.559 --> 00:18:37.080 align:start position:19%
to get the string values of this what
I'm going to do is I'm going to go back

00:18:34.880 --> 00:18:40.480 align:start position:19%
to my original code just in case I broke
something up here as I was de

00:18:38.559 --> 00:18:44.880 align:start position:19%
obfuscating this and let's run this
inside of our console so we can declare

00:18:42.440 --> 00:18:49.600 align:start position:19%
these functions and have this function
invocation so we can get the real

00:18:47.039 --> 00:18:52.760 align:start position:19%
corresponding values of the array now
I'm pretty confident this isn't doing

00:18:51.000 --> 00:18:56.640 align:start position:19%
anything malicious this is just some
setup code for the malware but again I'm

00:18:54.880 --> 00:19:00.200 align:start position:19%
running this inside of my secure malware
analysis environment so I'm not too

00:18:58.280 --> 00:19:04.240 align:start position:19%
worried if do accidentally execute
something kind of

00:19:01.480 --> 00:19:08.640 align:start position:19%
malicious let me go over to my code and
let's just add our function definitions

00:19:06.520 --> 00:19:14.120 align:start position:19%
to our developer tools so I'm going to
paste this in add that

00:19:11.640 --> 00:19:18.799 align:start position:19%
function go over to our other
function and our

00:19:16.520 --> 00:19:22.480 align:start position:19%
variable paste this in remember this is
the original malicious code before I

00:19:20.559 --> 00:19:26.440 align:start position:19%
started deop fisting just in case I
broke something and then I'm going to

00:19:24.840 --> 00:19:30.520 align:start position:19%
run this function and this should
effectively rearrange all of the

00:19:28.360 --> 00:19:34.360 align:start position:19%
elements inside of the array so that we
can get their real values down here

00:19:32.880 --> 00:19:39.120 align:start position:19%
inside of the function that's doing the
primary work of this malicious code I'm

00:19:37.520 --> 00:19:44.360 align:start position:19%
going to copy
this and let's just dump this inside of

00:19:41.760 --> 00:19:48.440 align:start position:19%
here and have that execute looks like
we're good this executed properly and

00:19:46.360 --> 00:19:54.159 align:start position:19%
didn't have any kind of Errors now we
should be able to go over back to our

00:19:51.360 --> 00:19:57.520 align:start position:19%
code and take some of the function calls
inside of here and get their real

00:19:55.559 --> 00:20:02.080 align:start position:19%
corresponding values the first thing
that I want to change is down here and

00:19:59.440 --> 00:20:06.799 align:start position:19%
this is going to get the array index of
all of our commands and then get the

00:20:03.960 --> 00:20:11.679 align:start position:19%
string at that specified index which is
specified by this heximal value down

00:20:08.960 --> 00:20:16.240 align:start position:19%
here now remember I pasted in the
commands from the original value before

00:20:14.200 --> 00:20:19.520 align:start position:19%
I started changing variable names so
what I want to do is instead of pasting

00:20:17.919 --> 00:20:22.919 align:start position:19%
this in I'm going to find the original
method name of this then I'm just going

00:20:21.200 --> 00:20:27.360 align:start position:19%
to print this to the console to see what
the string value really

00:20:24.799 --> 00:20:32.120 align:start position:19%
is I'm going to take this go to our
ActiveX object

00:20:29.200 --> 00:20:35.520 align:start position:19%
copy this method call let's go to our
developer tools and I'm just going to do

00:20:36.600 --> 00:20:44.000 align:start position:19%
console.log paste that in and there we
go that's the real string value that

00:20:41.559 --> 00:20:49.600 align:start position:19%
it's returning so I can copy
this and just replace

00:20:47.440 --> 00:20:55.600 align:start position:19%
this and then we're concatenating
another string so I'm going to copy this

00:20:52.080 --> 00:20:55.600 align:start position:19%
oop let me put this in the correct

00:20:56.000 --> 00:21:02.440 align:start position:19%
location inside of our deop fiscated
code

00:20:59.880 --> 00:21:07.159 align:start position:19%
there we go I'm going to take this
second value of this and print that to

00:21:04.520 --> 00:21:07.159 align:start position:19%
the console as

00:21:09.600 --> 00:21:15.400 align:start position:19%
well and that's the second portion of
our string that we're concatenating

00:21:15.880 --> 00:21:22.000 align:start position:19%
together so we can actually get rid of
this and simply put this to the end of

00:21:20.039 --> 00:21:25.960 align:start position:19%
the string so now we see we're creating
a new active X object and this is going

00:21:24.120 --> 00:21:29.640 align:start position:19%
to take some commands that are going to
be executed on the system so these are

00:21:27.799 --> 00:21:33.240 align:start position:19%
going to be taking some shell commands
this is really exciting because this is

00:21:31.400 --> 00:21:37.039 align:start position:19%
probably executing the malicious portion
of our code now continuing on I'm going

00:21:35.679 --> 00:21:40.720 align:start position:19%
to do the same kind of thing and I'm
just going to replace all of the strings

00:21:38.799 --> 00:21:44.400 align:start position:19%
inside of this all of these method
invocations with their real string

00:21:42.480 --> 00:21:47.520 align:start position:19%
values and do this over and over and
over again which is a really manual

00:21:46.200 --> 00:21:52.120 align:start position:19%
process I'm going to speed through the
portion of this since it becomes very

00:21:49.240 --> 00:21:55.320 align:start position:19%
repetitive after I do the first two let
me take a look at the first one first of

00:21:53.679 --> 00:21:59.919 align:start position:19%
all let's rename our
variable since we're passing in a

00:21:57.840 --> 00:22:04.159 align:start position:19%
reference to method so again this is
just our get command string at index

00:22:02.200 --> 00:22:09.840 align:start position:19%
we're just deating some more
strings I'm going to call

00:22:06.840 --> 00:22:09.840 align:start position:19%
this

00:22:10.520 --> 00:22:17.559 align:start position:19%
bar get
command string at index so it's

00:22:15.559 --> 00:22:22.400 align:start position:19%
effectively invoking that method this is
just not a regular variable and we'll

00:22:20.000 --> 00:22:26.120 align:start position:19%
replace all occurrences of that so that
it's much clearer for us to see and now

00:22:24.679 --> 00:22:30.720 align:start position:19%
I'm going to go through and I'm going to
print out each of these values remember

00:22:28.240 --> 00:22:35.080 align:start position:19%
I'm going to go back to my old code down
here and print this since this is the

00:22:33.320 --> 00:22:38.679 align:start position:19%
original variable name that I used
inside of the code I was executing

00:22:36.559 --> 00:22:41.679 align:start position:19%
inside of my console now first thing I'm
going to do is I'm going to set this new

00:22:40.200 --> 00:22:46.480 align:start position:19%
variable that we're using through all of
these occurrences I'm going to set this

00:22:43.320 --> 00:22:51.799 align:start position:19%
equal to our function so we'll copy
this put this inside of our

00:22:49.000 --> 00:22:55.400 align:start position:19%
console and now we can invoke that
method since this is an indirect

00:22:53.360 --> 00:23:01.640 align:start position:19%
reference to that method we'll just do
console.log and we'll print out the

00:22:56.919 --> 00:23:01.640 align:start position:19%
string value of this console.

00:23:01.960 --> 00:23:08.120 align:start position:19%
log here we go now that's the string let
me do the second portion of

00:23:10.360 --> 00:23:15.840 align:start position:19%
this same thing console.log

00:23:15.919 --> 00:23:22.480 align:start position:19%
this and this should all start getting a
little bit clearer it's a very exciting

00:23:23.000 --> 00:23:29.440 align:start position:19%
process and that's the second portion of
our

00:23:26.799 --> 00:23:33.840 align:start position:19%
string since it's catenated we can just
put it together now this looks like a

00:23:31.600 --> 00:23:37.480 align:start position:19%
map that is defining a key and then
value pair so the key is going to be

00:23:35.799 --> 00:23:41.159 align:start position:19%
this string and the value is going to be
the corresponding string that is the

00:23:39.279 --> 00:23:46.480 align:start position:19%
second one following it now I'm going to
speed through and do the same thing for

00:23:42.559 --> 00:23:46.480 align:start position:19%
all of these different values inside of

00:23:47.540 --> 00:23:51.310 align:start position:19%
[Music]
[Applause]

00:23:51.679 --> 00:23:57.120 align:start position:19%
here now I've gone through and I've
changed all of those method references

00:23:55.440 --> 00:24:01.279 align:start position:19%
over to Strings and you can see the
execution flow is getting way way

00:23:59.000 --> 00:24:05.720 align:start position:19%
clearer already this is really exciting
we've got our map with key value Pairs

00:24:03.360 --> 00:24:10.120 align:start position:19%
and you can see we're calling this map
which is being defin over here and then

00:24:07.799 --> 00:24:14.520 align:start position:19%
looking for the key and then replacing
those commands and we're using our

00:24:12.039 --> 00:24:18.520 align:start position:19%
ActiveX object to run commands on the
underlying system the commands are going

00:24:16.400 --> 00:24:22.559 align:start position:19%
to be coming from up here now what I
want to do is I want to change the key

00:24:20.440 --> 00:24:26.880 align:start position:19%
calls over to their corresponding
strings so let me show one example of

00:24:24.960 --> 00:24:31.799 align:start position:19%
doing this this is really simple all I
need to do is find the key here and then

00:24:29.200 --> 00:24:35.000 align:start position:19%
replace that call to the corresponding
string this is going to be the

00:24:33.159 --> 00:24:39.919 align:start position:19%
corresponding
value replace that I'm going to perform

00:24:37.640 --> 00:24:43.360 align:start position:19%
the same operation for all references to
this map and just replace with the

00:24:41.520 --> 00:24:48.279 align:start position:19%
corresponding strings again I'm going to
speed through this process since it gets

00:24:44.880 --> 00:24:48.279 align:start position:19%
a little bit tedious and a little bit

00:24:52.799 --> 00:24:59.080 align:start position:19%
manual now I finished replacing all
references to this map with their

00:24:56.640 --> 00:25:02.799 align:start position:19%
corresponding values and looking for a
key I simply replaced with the value

00:25:00.840 --> 00:25:06.240 align:start position:19%
instead to make it much more readable
and you can see we've got this kind of

00:25:04.360 --> 00:25:10.320 align:start position:19%
clear string of commands that it looks
like we're concatenating inside of this

00:25:08.320 --> 00:25:14.559 align:start position:19%
variable before we execute them on the
underlying system we are referencing our

00:25:12.760 --> 00:25:19.320 align:start position:19%
ActiveX object and it looks like we're
going to pass in our Command string and

00:25:16.919 --> 00:25:23.399 align:start position:19%
execute that on the system now the final
thing we need to do for this is actually

00:25:21.200 --> 00:25:26.919 align:start position:19%
put our commands together instead of
being part of this WOW Loop that's going

00:25:25.039 --> 00:25:31.720 align:start position:19%
to put our commands inside of this
variable I'm going to go go through and

00:25:28.799 --> 00:25:37.000 align:start position:19%
do that let's first rename this variable
let's call this

00:25:32.880 --> 00:25:37.000 align:start position:19%
VAR command to

00:25:37.480 --> 00:25:43.760 align:start position:19%
execute now this is a little bit of
another obfuscation Technique we have

00:25:41.720 --> 00:25:48.120 align:start position:19%
this WOW Loop and we're putting together
all of these command strings based off

00:25:45.760 --> 00:25:52.279 align:start position:19%
of this switch case we're defining our
switch case up here this is going to be

00:25:50.200 --> 00:25:56.039 align:start position:19%
our string that we're looking at and it
looks like this is our index value first

00:25:54.320 --> 00:26:04.120 align:start position:19%
of all let me clarify
this go over here let's just do console.

00:26:01.440 --> 00:26:09.360 align:start position:19%
log for this integer value just the
integer zero very simple so I'm going to

00:26:06.679 --> 00:26:09.360 align:start position:19%
replace that with

00:26:10.480 --> 00:26:21.760 align:start position:19%
zero this is going to be our index
rename that to far

00:26:17.320 --> 00:26:27.240 align:start position:19%
index much clearer the last thing is our
string now this is our index string I'm

00:26:24.080 --> 00:26:30.240 align:start position:19%
going to rename this as well just for
Simplicity

00:26:30.840 --> 00:26:37.320 align:start position:19%
and this is a little bit funky if you go
through the string we're splitting this

00:26:34.799 --> 00:26:41.360 align:start position:19%
based off of this character right here
and then we're going through index by

00:26:39.279 --> 00:26:45.880 align:start position:19%
index for the string that is stored
inside of this so each of these is the

00:26:44.039 --> 00:26:50.480 align:start position:19%
index that we're going to be using for
this switch statement so case Zero is

00:26:48.279 --> 00:26:55.840 align:start position:19%
going to append this command case one is
going to append this command but our

00:26:52.720 --> 00:27:00.919 align:start position:19%
cases are defined by these values inside
of the string so what we need to do in

00:26:57.919 --> 00:27:04.840 align:start position:19%
actually Duality is start from four 3
then go to one and append those commands

00:27:03.720 --> 00:27:09.919 align:start position:19%
so what I'm going to do is I'm going to
take this we start at four so I'm going

00:27:07.720 --> 00:27:16.480 align:start position:19%
to take this string let's put this over
into a new file for

00:27:13.399 --> 00:27:19.200 align:start position:19%
Simplicity let's move this over here now
these are going to be the commands are

00:27:17.720 --> 00:27:24.039 align:start position:19%
run that are running on the actual
underlying system so we start with four

00:27:22.360 --> 00:27:30.159 align:start position:19%
then we go over to
three we can append these

00:27:27.159 --> 00:27:30.159 align:start position:19%
commands

00:27:31.480 --> 00:27:39.159 align:start position:19%
there we
go then the next one is

00:27:35.279 --> 00:27:39.159 align:start position:19%
one I'm going to copy this

00:27:41.279 --> 00:27:46.760 align:start position:19%
over there we go and then we can keep
going in order I hope you're getting the

00:27:45.080 --> 00:27:49.640 align:start position:19%
hang of this and see what I'm doing
again I'm going to speed through this

00:27:47.880 --> 00:27:52.120 align:start position:19%
portion so that we can just get this
process

00:27:56.679 --> 00:28:02.880 align:start position:19%
complete now I have my full set of
commands that I put in the correct order

00:28:00.960 --> 00:28:08.120 align:start position:19%
on the right hand side and let's just
walk through the actual behavior of this

00:28:05.320 --> 00:28:13.360 align:start position:19%
sample now the last two indices that we
look at are two and 8 so if we go at

00:28:10.880 --> 00:28:19.399 align:start position:19%
case two this is using our active X
object to execute a command on the

00:28:15.440 --> 00:28:19.399 align:start position:19%
system let's clarify this number real

00:28:20.120 --> 00:28:29.279 align:start position:19%
quick and print the integer value just
the integer

00:28:24.840 --> 00:28:34.840 align:start position:19%
zero so we can replace this with
zero same thing down here let me clarify

00:28:32.399 --> 00:28:34.840 align:start position:19%
this real

00:28:37.480 --> 00:28:42.240 align:start position:19%
quick just the integer value one very
simple

00:28:44.200 --> 00:28:49.840 align:start position:19%
beautiful
perfect now we have the commands that

00:28:48.120 --> 00:28:54.159 align:start position:19%
we're building up and we do this in
order from here then we go to case

00:28:52.159 --> 00:28:58.360 align:start position:19%
number two which is using our active X
object to run a command in the

00:28:56.159 --> 00:29:03.159 align:start position:19%
background the command to execute is
going to be this Powershell command

00:29:00.399 --> 00:29:08.600 align:start position:19%
which is going to take a JPEG from this
malicious IP address download it put it

00:29:06.080 --> 00:29:13.679 align:start position:19%
inside of this ZIP file expand that
archive and then push this into the C

00:29:11.120 --> 00:29:17.799 align:start position:19%
users public folder and then once we
finished with this case we're moving on

00:29:15.320 --> 00:29:23.440 align:start position:19%
to the last Case Case 8 which is going
to run something called C userpublic

00:29:20.440 --> 00:29:28.960 align:start position:19%
shell. JS so we're putting this and
expanding it into this shell. JS now all

00:29:27.240 --> 00:29:33.279 align:start position:19%
this was doing was this is a really
complicated way of downloading a

00:29:30.840 --> 00:29:37.760 align:start position:19%
malicious file from an IP address
expanding this putting this inside of

00:29:35.000 --> 00:29:41.600 align:start position:19%
this shell. JS file and then executing
that as the final payload let me take a

00:29:40.000 --> 00:29:45.240 align:start position:19%
look at this IP address it's very
interesting I want to double check in

00:29:43.200 --> 00:29:49.600 align:start position:19%
virus total and see what other people
think about this let's just go to virus

00:29:49.880 --> 00:29:56.880 align:start position:19%
total and dump this in and see and
verify that this is indeed malicious I'm

00:29:55.399 --> 00:30:01.600 align:start position:19%
going to paste in this
IP and and here we go this is definitely

00:29:59.320 --> 00:30:05.440 align:start position:19%
malicious so this is probably holding a
malicious payload that is going to be

00:30:03.080 --> 00:30:09.440 align:start position:19%
downloaded and executed on the victim's
machine and my guess is it's going to be

00:30:07.399 --> 00:30:14.480 align:start position:19%
that async R payload it's going to
remotely let the attacker access control

00:30:12.679 --> 00:30:18.679 align:start position:19%
and send commands to the victim's
machine Let's Take a final look at the

00:30:16.200 --> 00:30:23.120 align:start position:19%
deop fiscated file remember this was the
original form of the file all on one

00:30:20.640 --> 00:30:26.880 align:start position:19%
line and heavily OB fiscated and this is
the deop fiscated portion where we

00:30:25.039 --> 00:30:30.519 align:start position:19%
renamed all of the variables we replaced
all of the strings we ordered the

00:30:28.559 --> 00:30:35.000 align:start position:19%
command string so that we could see what
commands were getting executed in the

00:30:32.360 --> 00:30:38.000 align:start position:19%
proper order of execution so we go
through here looks so much better looks

00:30:37.159 --> 00:30:41.919 align:start position:19%
really
beautiful and then these were the final

00:30:40.039 --> 00:30:45.480 align:start position:19%
commands that get executed where we're
downloading a file and then executing it

00:30:43.720 --> 00:30:48.150 align:start position:19%
on the victim system so thanks so much
for watching Lori wired everyone and

00:30:46.720 --> 00:30:51.349 align:start position:19%
I'll catch you in the next
[Music]

00:30:53.360 --> 00:31:01.359 align:start position:19%
video you would require like miracle
[Music]

00:31:01.480 --> 00:31:07.540 align:start position:19%
20 seconds
[Music]

00:31:05.399 --> 00:31:13.360 align:start position:19%
behind
[Music]

00:31:10.360 --> 00:31:13.360 align:start position:19%
gosh

