In order to submit a login form using wget
, I need to find the values for the hidden field that were added to the form recently. Grepping for the names gives the following:
$ grep csrf signin.php
<input type="hidden" name="csrf1" value="56a0ecec3f15c" />
<input type="hidden" name="csrf2" value="4a8cb442fc85a745c9cf92edd44d71cc3ac7225e99acf57d67276ea0481f9ae8" />
<input type="hidden" name="csrf1" value="56a0ecec3f236" />
<input type="hidden" name="csrf2" value="292f226a5048c3d75dcfc28c8e05df49089d55160ff37e5572ecb51e208a1e52" />
<input type="hidden" name="csrf1" value="56a0ecec3f399" />
<input type="hidden" name="csrf2" value="a99e22c2361505931a8e26f40d26de156b928b9d218fbe4f02a98f15e2364269" />
I need to extract the two middle values for csrf1 and csrf2, and concatenate them into something that looks like the following, all on one line:
csrf1=56a0ecec3f236&csrf2=292f226a5048c3d75dcfc28c8e05df49089d55160ff37e5572ecb51e208a1e52
What I came up with, using bash
, is the following:
CSRF=`grep csrf signin.php | tail -4 | head -2 | awk -F "\"" '{print $4 "=" $6}'`
CSRF=`echo $CSRF | sed -e 's/ /\&/'`
How would you improve these two lines?