File: http_more.pm

package info (click to toggle)
doona 1.0%2Bgit20190108-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 276 kB
  • sloc: perl: 2,287; makefile: 4; sh: 1
file content (122 lines) | stat: -rw-r--r-- 4,260 bytes parent folder | download | duplicates (2)
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
package bedmod::http_more;
use Socket;

# This package is an extension to doona, to check
# for http server vulnerabilities.
#
# Tests for request methods and request fields not tested in the standard http module

# Written by Grid

sub new {
    my $this = {};
    bless $this;
    return $this;
}

sub init {
    my $this = shift;
    %special_cfg=@_;

    $this->{proto}="tcp";

    if ($special_cfg{'p'} eq "") {
        $this->{port}='80';
    } else {
        $this->{port} = $special_cfg{'p'};
    }

    if ($special_cfg{'d'}) { return; }
    $iaddr = inet_aton($this->{target})             || die "Unknown host: $host\n";
    $paddr = sockaddr_in($this->{port}, $iaddr)     || die "getprotobyname: $!\n";
    $proto = getprotobyname('tcp')                  || die "getprotobyname: $!\n";
    socket(SOCKET, PF_INET, SOCK_STREAM, $proto)    || die "socket: $!\n";
    connect(SOCKET, $paddr)                         || die "connection attempt failed: $!\n";
    send(SOCKET, "HEAD / HTTP/1.0\r\n\r\n", 0)      || die "HTTP request failed: $!\n";
}

sub health_check {
    my $this = shift;
    $iaddr = inet_aton($this->{target})             || die "Unknown host: $this->{target}\n";
    $paddr = sockaddr_in($this->{port}, $iaddr)     || die "getprotobyname: $!\n";
    $proto = getprotobyname('tcp')                  || die "getprotobyname: $!\n";
    socket(SOCKET, PF_INET, SOCK_STREAM, $proto)    || die "socket: $!\n";
    connect(SOCKET, $paddr)                         || die "connection attempt failed: $!\n";
    send(SOCKET, "HEAD / HTTP/1.0\r\n\r\n", 0)      || die "HTTP request failed: $!\n";
    my $resp = <SOCKET>;
    if (!$this->{healthy}) {
          if ($resp =~ /HTTP/) {
              $this->{healthy}=$resp;
          }
          # print "Set healthy: $resp";
    }
    return $resp =~ m/^$this->{healthy}$/;
}

sub getQuit {
    return("\r\n\r\n");
}

sub getLoginarray {
    my $this = shift;
    @Loginarray = (
        "GET /default.XAXAX HTTP/1.1\r\nHost: 192.168.43.128\r\n\r\n",
        "GET /XAXAX.html HTTP/1.1\r\nHost: 192.168.43.128\r\n\r\n",        
        "CONNECT XAXAX:80 HTTP/1.1\r\n\r\n",
        "CONNECT 192.168.43.128/home:XAXAX HTTP/1.1\r\n\r\n",
        "PATCH /XAXAX HTTP/1.1\r\nHost: 192.168.43.128\r\n\r\n",          
      );
    return (@Loginarray);
}

sub getCommandarray {
    my $this = shift;

    @cmdArray = (
        "Accept-Datetime: XAXAX\r\nHost: 192.168.43.128\r\n\r\n",
        "Cache-Control: XAXAX\r\nHost: 192.168.43.128\r\n\r\n",
        "Content-MD5: XAXAX\r\nHost: 192.168.43.128\r\n\r\n",
        "Content-Type: XAXAX\r\nHost: 192.168.43.128\r\n\r\n",
        "Date: XAXAX\r\n\r\n",
        "Forwarded: XAXAX\r\nHost: 192.168.43.128\r\n\r\n",
        "Origin: XAXAX\r\nHost: 192.168.43.128\r\n\r\n",
        "Via: XAXAX\r\nHost: 192.168.43.128\r\n\r\n",
        "Warning: XAXAX\r\nHost: 192.168.43.128\r\n\r\n",
        "X-Requested-With: XAXAX\r\nHost: 192.168.43.128\r\n\r\n",
        "DNT: XAXAX\r\nHost: 192.168.43.128\r\n\r\n",       
        "X-Forwarded-For: XAXAX\r\nHost: 192.168.43.128\r\n\r\n",
        "X-Forwarded-Host: XAXAX\r\nHost: 192.168.43.128\r\n\r\n",
        "X-Forwarded-Proto: XAXAX\r\nHost: 192.168.43.128\r\n\r\n",
        "Front-End-Https: XAXAX\r\nHost: 192.168.43.128\r\n\r\n",
        "X-Http-Method-Override: XAXAX\r\nHost: 192.168.43.128\r\n\r\n",
        "X-Att-Deviceid: XAXAX\r\nHost: 192.168.43.128\r\n\r\n",
        "X-Wap-Profile: XAXAX\r\nHost: 192.168.43.128\r\n\r\n",
        "Proxy-Connection: XAXAX\r\nHost: 192.168.43.128\r\n\r\n",
        "X-UIDH: XAXAX\r\nHost: 192.168.43.128\r\n\r\n",
        "X-Csrf-Token: XAXAX\r\nHost: 192.168.43.128\r\n\r\n",        
      );
    return(@cmdArray);
}

sub getLogin {
    my $this = shift;
    @login = (        
        "CONNECT 192.168.43.128:80 HTTP/1.1\r\n",
        "PATCH /default.html HTTP/1.1\r\n",
      );
    return(@login);
}

sub testMisc {         #Put your corner case tests here
    my $this = shift;
    @cmdArray = (      
        "CONNECT 192.168.43.128:80 HTTP/1.1\r\n" . "Lotsofheaders: XAXAX\r\n" x 1024 . "\r\n",
        "PATCH / HTTP/1.1\r\nHost: 192.168.43.128\r\n\r\n" . "Lotsofheaders: XAXAX\r\n" x 1024 . "\r\n",
      );
    return(@cmdArray);
}

sub usage {
}

1;