Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    Curl/Wget script login dealing with CSRF

    Scheduled Pinned Locked Moved webGUI
    2 Posts 1 Posters 2.8k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      stompro
      last edited by

      Hello, can someone share how they are dealing with the CSRF feature of the login screen on 2.1.

      I have a few scripts that allow local users to execute the wol feature of the firewall, so they can start machines in all the various vlans at their location.  Those scripts stopped working after I upgraded the site to pfSense 2.1.  I just get an error about the token.. or a 403:Forbidden

      The instructions for 2.0 at the following site no longer seem to work.  Do they work for you?
      https://doc.pfsense.org/index.php/Remote_Config_Backup

      Do I need to grab the login page first, then grab the CSRF token, then submit the login form using that token?  Anyone have a vbasic script that does that already.  I'm just looking for something that runs on windows 7 using the standard tools that come with it, + curl.

      Thanks
      Josh

      Hardware used: Alix 2D13 X 10, APU2D4 X 10, SG-2200 X 10, SG-2440 X 4

      1 Reply Last reply Reply Quote 0
      • S
        stompro
        last edited by

        Here is the start of a powershell script to log in, anyone have any suggestions on getting it to actually work?

        #Firewall Hostname
        $fwhost = "https://firewall.org.org"
        #Firewall Login Name
        $fwlogin = "admin"
        #Password
        $fwpw = "tacos"
        
        $curlout = [string](.\curl\curl.exe -k -s -c cookies.txt $fwhost)
        $curlout -match "(sid:.{106})"
        
        $curlcmd = ".\curl\curl.exe -k -s -b cookies.txt -d login=Login&usernamefld=${fwlogin}&passwordfld=${fwpw}&__csrf_magic=$($matches[0]) ${fwhost}/services_wol.php"
        
        echo $curlcmd
        
        $curlout = [string](.\curl\curl.exe -k -s -i -b cookies.txt -d "login=Login&usernamefld=${fwlogin}&passwordfld=${fwpw}&__csrf_magic=$($matches[0])" ${fwhost}/services_wol.php)
        
        echo $curlout
        
        

        Hardware used: Alix 2D13 X 10, APU2D4 X 10, SG-2200 X 10, SG-2440 X 4

        1 Reply Last reply Reply Quote 0
        • First post
          Last post
        Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.