News: This forum is now permanently frozen.
Pages: 1 [2] 3
Topic: Unable to backup via wget or curl on 1.34  (Read 11911 times)
« Reply #15 on: February 20, 2013, 15:53:50 »
Lennart Grahl ***
Posts: 153

Example for exec_raw.php:

Code:
Note: for CSRF protection, this script cannot be called directly with a
GET parameter anymore. You must first call the script (GET) without any parameters
to obtain a current token, and then call it again (POST) while passing the token
value as the parameter __csrf_magic.

Minimal example in Perl:

#!/usr/bin/perl

use LWP::UserAgent;

my $m0n0wall_ip = "192.168.1.1";
my $m0n0wall_user = "admin";
my $m0n0wall_pass = "mono";
my $cmd = "dmesg";

my $ua = LWP::UserAgent->new;
$ua->credentials("$m0n0wall_ip:80", ".", $m0n0wall_user, $m0n0wall_pass);

# get new CSRF magic token
my $res = $ua->get("http://$m0n0wall_ip/exec_raw.php");
my $csrftoken = $res->content;

# make a request to exec_raw.php
$res = $ua->post("http://$m0n0wall_ip/exec_raw.php", {
'__csrf_magic' => $csrftoken,
'cmd' => $cmd
});
print $res->content;
« Reply #16 on: February 28, 2013, 21:10:37 »
sysmcn *
Posts: 2

I appreciate all that I can provide ayua Thanks Lennart Grahl "put the example do not understand, this echo with (perl) and this programming language I do not understand anyway I missing something because I see in the code where prompted to download the file "diag_backup.php" I do not see how I can apply this code, grateful to the community or a complete code in another language such as VB for backups as Monowall version 1.34. Smiley Smiley
« Reply #17 on: March 20, 2013, 13:27:45 »
doownek *
Posts: 12

When I do a wget on exec_raw.php I get this response:

sid:aa52f375fc07e5df8b1746175b4f1ac626299fb9,1363773100;ip:e04e9a872ab8132caa05208db64e159ca0ff6fda,1363773100

When I do a similar request on diag_backup.php I just get the code, so I guess I'm supposed to use the response above?

I try to send it like this:
Code:
/usr/bin/wget --post-data "Submit=Download%20configuration&__csrf_magic=sid:aa52f375fc07e5df8b1746175b4f1ac626299fb9,1363773100;ip:e04e9a872ab8132caa05208db64e159ca0ff6fda,1363773100" --auth-no-challenge --no-check-certificate --http-user=user --http-password=password -q https://10.x.x.10:444/diag_backup.php

but it doesn't work. Can anyone see what is wrong?
« Reply #18 on: March 25, 2013, 14:24:25 »
bik0z *
Posts: 2

Hi all,

I've been trying to make the example code work with the reboot.php page with no luck.

Am I missing something obvious? Thanks in advance.

Code:
#!/usr/bin/perl

use LWP::UserAgent;

my $m0n0wall_ip = "192.168.1.1";
my $m0n0wall_user = "admin";
my $m0n0wall_pass = "mono";

my $ua = LWP::UserAgent->new;
$ua->credentials("$m0n0wall_ip:80", ".", $m0n0wall_user, $m0n0wall_pass);

# get new CSRF magic token
my $res = $ua->get("http://$m0n0wall_ip/reboot.php");

my @content = split(/\n/, $res->content);

for (@content) {
    if ( m/sid:(.+);ip/ ) {
        my $csrftoken = "sid:$1";
    }
}

# make a request to reboot.php
$res = $ua->post("http://$m0n0wall_ip/reboot.php", {
        '__csrf_magic' => $csrftoken,
        'Submit' => " Yes "
});

« Reply #19 on: July 25, 2013, 10:32:29 »
doownek *
Posts: 12

Does anyone have an answer here?
« Reply #20 on: July 25, 2013, 11:03:17 »
bik0z *
Posts: 2

Not sure if this is what people are looking for, but the following Perl code allows me to remotely reboot multiple routers at once.

I hope this helps.

PS : Manuel Kasper was kind enough to help me debug my poor Perl code...


Code:
#!/usr/bin/perl

use LWP::UserAgent;

my $m0n0wall_user = "admin";
my $m0n0wall_pass = "mono";

foreach my $m0n0wall_ip ('192.168.2.254', '192.168.3.254', '192.168.4.254', '192.168.1.254',)
{
        my $ua = LWP::UserAgent->new;
        $ua->credentials("$m0n0wall_ip:80", ".", $m0n0wall_user, $m0n0wall_pass);

        my $res = $ua->get("http://$m0n0wall_ip/reboot.php");
        my @content = split(/\n/, $res->content);

        my $csrftoken;
        for (@content) {
                if ( m/"(sid:.+?)"/ ) {
                        $csrftoken = $1;
                }
        }

        $res = $ua->post("http://$m0n0wall_ip/reboot.php", {
                        '__csrf_magic' => $csrftoken,
                        'Submit' => " Yes "
        });

        sleep(1);
}

# EOF

« Reply #21 on: August 16, 2013, 14:55:42 »
doownek *
Posts: 12

This works for me:
First:
Code:
wget --no-check-certificate -q --keep-session-cookies --save-cookies ./cookies.txt --post-data  login=Login&usernamefld=<your_username>&passwordfld=<your_password>' -O /dev/null https://<IP Address>:<Port>/diag_backup.php

Then:
Code:
wget --no-check-certificate -q --keep-session-cookies --load-cookies ./cookies.txt --post-data Submit=Download%20configuration https://<IP Address>:<Port>/diag_backup.php -O <Output file>
« Reply #22 on: August 30, 2013, 20:07:59 »
amee *
Posts: 24

dont work this method from wget in windows   Sad Sad Sad
« Reply #23 on: August 30, 2013, 21:01:46 »
Lee Sharp *****
Posts: 517

Can you show us what you are doing and what the response is?
« Reply #24 on: September 02, 2013, 18:28:11 »
amee *
Posts: 24

//Windows server 2008r2// CMD file //

wget http://1.1.1.1:80/diag_backup.php -d --keep-session-cookies --save-cookies=cookies.txt --post-data  `login=Login^&usernamefld=asdmin^&passwordfld=12345` --http-user=admin --http-passwd=123456 -O -

wget http://1.1.1.1:80/diag_backup.php -d --keep-session-cookies --save-cookies=cookies.txt --post-data  login=Login^&usernamefld=asdmin^&passwordfld=1234 -O -

wget http://1.1.1.1:80/diag_backup.php --save-cookies=cookies.txt -q --keep-session-cookies --no-check-certificate --http-user=admin --http-passwd=12345 --post-data Submit=Download%20configuration -O -


I tried to make different choices, but it does not help.

after i have wrong cookies

1.1.1.1   FALSE   /   FALSE   0   PHPSESSID   1c8e76757e5e12f6774eg73e51649ae1f

and next, where upload cookies command  - dont work, of corse.
« Reply #25 on: September 02, 2013, 20:07:55 »
Lee Sharp *****
Posts: 517

Now I can't get it to work either...  I will dig.
« Reply #26 on: September 02, 2013, 20:11:59 »
amee *
Posts: 24

can i help u?
« Reply #27 on: September 03, 2013, 14:43:52 »
Lee Sharp *****
Posts: 517

I have been on the mailing list since 2005.  I am searching old e-mails, and trying a few things.  As it is on the side, however, it may take a while. Smiley

Anyone else with it working, feel free to chime in!
« Reply #28 on: September 03, 2013, 16:09:36 »
Lennart Grahl ***
Posts: 153

dont work this method from wget in windows   Sad Sad Sad

Unless you are using an older version of m0n0wall you have to supply the "__csrf_magic"-token to your second request as post data.
Otherwise it will not work at all.
« Reply #29 on: September 05, 2013, 07:41:19 »
amee *
Posts: 24

I do not understand how it should be used.
« Last Edit: September 05, 2013, 08:21:39 by amee »
 
Pages: 1 [2] 3
 
 
Powered by SMF 1.1.20 | SMF © 2013, Simple Machines