WEBVTT

00:00:00.666 --> 00:00:04.066
Troubleshooting the
“index out of range” Error

00:00:05.633 --> 00:00:10.166
As we found during the previous section,
the Python interpreter has thrown an error

00:00:10.166 --> 00:00:13.300
related to line 24 of
our modified exploit.

00:00:18.300 --> 00:00:21.866
Inspecting this line, we’ll notice
that it uses the split method

00:00:21.866 --> 00:00:25.400
in order to slice the string stored
in the location parameter

00:00:25.400 --> 00:00:28.833
passed to the
parse_csrf_token function.

00:00:41.566 --> 00:00:43.666
The Python documentation for split

00:00:43.666 --> 00:00:47.366
indicates that this method
slices the input string,

00:00:48.133 --> 00:00:52.266
using an optional separator
passed as a first argument.

00:00:53.166 --> 00:00:58.866
The string slices returned by split
are then stored in a Python list object,

00:01:01.533 --> 00:01:04.233
that can be accessed via an index.

00:01:13.333 --> 00:01:19.333
In our exploit code, the string separator
is defined as the csrf_param variable

00:01:19.333 --> 00:01:21.300
followed by the equals sign.

00:01:22.033 --> 00:01:24.000
In order to better
understand the IndexError,

00:01:24.000 --> 00:01:28.333
we can add a print statement in the
parse_csrf_token function

00:01:28.333 --> 00:01:30.266
before the return instruction.

00:01:43.266 --> 00:01:48.633
The exploit now displays the full string
before the split method is invoked.

00:01:48.900 --> 00:01:53.166
While the exploit code expected
the input string to contain “c”,

00:01:53.166 --> 00:01:56.733
we received “sk” from the web application.

00:01:57.533 --> 00:02:01.066
At this point, we don’t fully
understand why this is happening.

00:02:01.300 --> 00:02:03.533
Perhaps there is a version mismatch

00:02:03.533 --> 00:02:06.700
between the exploit
developer’s software and ours,

00:02:06.700 --> 00:02:09.466
or a CMS configuration mismatch.

00:02:09.666 --> 00:02:14.433
In any case, we know that exploit
development is never straightforward.

00:02:21.133 --> 00:02:26.766
Next, let’s try to change the csrf_param
variable to match the CMS response

00:02:26.766 --> 00:02:29.133
to find out if the exploit works.

00:02:39.866 --> 00:02:42.633
Next, we’ll execute the modified exploit.

00:02:46.066 --> 00:02:49.900
The error is no longer displayed and
we are presented with a message

00:02:49.900 --> 00:02:53.266
 informing us that the
exploit has succeeded.

00:02:53.866 --> 00:02:55.966
Although we don’t clearly understand why

00:02:55.966 --> 00:02:58.533
we needed to change
the csrf_param variable,

00:02:58.533 --> 00:03:03.033
 this scenario showed us how
to adapt to unexpected situations,

00:03:03.033 --> 00:03:06.666
something great penetration
testers do very well.

00:03:07.933 --> 00:03:12.100
We can now validate the exploit
by attaching to the PHP shell

00:03:12.100 --> 00:03:17.700
with a tool like curl and supplying a
system command to serve as the payload:

00:03:19.400 --> 00:03:25.466
Nice! The exploit was successful,
and we now have a web shell.
