Skip to content

Commit

Permalink
Add: support for HTTP/2 (#1610)
Browse files Browse the repository at this point in the history
* Add: support for HTTP/2

See NASL manual documentation.

Jira: SC-1038

`openvas-nasl -X -t example.com http2.nasl`

```
h = http2_handle();
display(h);

r = http2_get(handle:h, port:443, item:"/", schema:"https");
display("response: ", r);
rc = http2_get_response_code(handle:h);
display("return code: ", rc);

http2_close_handle(h);

h = http2_handle();
display(h);

r = http2_get(handle:h, port:3000, item:"/vts", schema:"http");
display("response: ", r);
rc = http2_get_response_code(handle:h);
display("return code: ", rc);

http2_close_handle(h);
```

* nasl/nasl_http2.c

* small fix reported by clippy non related to this PR's topic

* fix typos
  • Loading branch information
jjnicola committed Apr 3, 2024
1 parent 6addc38 commit fc30c99
Show file tree
Hide file tree
Showing 17 changed files with 943 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# http2_close_handle

## NAME

**http2_close_handle** - Close a handle for http requests previously initialized.

## SYNOPSIS

*void* **http_close_handle**(handle: *int*);

**http_close_handle** takes one argument.

## DESCRIPTION
Close a handle for http requests previously initialized.

## RETURN VALUE
It returns an integer or NULL on error.

## EXAMPLES

**1** Close the handle identifier
```cpp
h = http2_handle();
display(h);
http2_close_handle(h);
```
## SEE ALSO
**[http2_delete(3)](http2_delete.md)**, **[http2_get(3)](http2_get.md)**, **[http2_close_handle(3)](http2_close_handle.md)**, **[http2_head(3)](http2_head.md)**, **[http2_handle(3)](http2_handle.md)**, **[http2_post(3)](http2_post.md)**, **[http2_put(3)](http2_put.md)**, **[http2_get_response_code(3)](http2_get_response_code.md)**, **[http2_set_custom_header(3)](http2_set_custom_header.md)**
37 changes: 37 additions & 0 deletions doc/manual/nasl/built-in-functions/http2-functions/http2_delete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# http2_delete

## NAME

**http2_delete** - performs an HTTP2 DELETE request for the server on the port.

## SYNOPSIS

*void* **http_delete**(handle: *int*, port: *int*, schema: *string*, item: *string*, data: *string*);

**http_delete** takes five named arguments.

## DESCRIPTION
Performs an HTTP2 DELETE request for the server on the port. It tries to force the version HTTP2 if `https` (default) is passed as schema uses ALPN to negotiate the protocol to use.

If `http` is passed as schema, the function includes an upgrade header in the initial request to the host to allow upgrading to HTTP/2.
The arguments are port and item (the path, query, etc), schema (optional, defualt `https`) and `data` (optional).

## RETURN VALUE
It returns a string (the http response). Null on error

## EXAMPLES

**1** Delete and display the formatted delete request:
```cpp
h = http2_handle();
display(h);

r = http2_delete(handle:h, port:3000, item:"/vts", schema:"http");
display("response: ", r);
rc = http2_get_response_code(handle:h);
display("return code: ", rc);
```
## SEE ALSO
**[http2_delete(3)](http2_delete.md)**, **[http2_get(3)](http2_get.md)**, **[http2_close_handle(3)](http2_close_handle.md)**, **[http2_head(3)](http2_head.md)**, **[http2_handle(3)](http2_handle.md)**, **[http2_post(3)](http2_post.md)**, **[http2_put(3)](http2_put.md)**, **[http2_get_response_code(3)](http2_get_response_code.md)**, **[http2_set_custom_header(3)](http2_set_custom_header.md)**
37 changes: 37 additions & 0 deletions doc/manual/nasl/built-in-functions/http2-functions/http2_get.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# http2_get

## NAME

**http2_get** - performs an HTTP2 GET request for the server on the port.

## SYNOPSIS

*void* **http_get**(handle: *int*, port: *int*, schema: *string*, item: *string*, data: *string*);

**http_get** takes five named arguments.

## DESCRIPTION
Performs an HTTP2 GET request for the server on the port. It tries to force the version HTTP2 if `https` (default) is passed as schema uses ALPN to negotiate the protocol to use.

If `http` is passed as schema, the function includes an upgrade header in the initial request to the host to allow upgrading to HTTP/2.
The arguments are port and item (the path, query, etc), schema (optional, defualt `https`) and `data` (optional).

## RETURN VALUE
It returns a string (the http response). Null on error

## EXAMPLES

**1** Get and display the formatted get request:
```cpp
h = http2_handle();
display(h);

r = http2_get(handle:h, port:3000, item:"/vts", schema:"http");
display("response: ", r);
rc = http2_get_response_code(handle:h);
display("return code: ", rc);
```
## SEE ALSO
**[http2_delete(3)](http2_delete.md)**, **[http2_get(3)](http2_get.md)**, **[http2_close_handle(3)](http2_close_handle.md)**, **[http2_head(3)](http2_head.md)**, **[http2_handle(3)](http2_handle.md)**, **[http2_post(3)](http2_post.md)**, **[http2_put(3)](http2_put.md)**, **[http2_get_response_code(3)](http2_get_response_code.md)**, **[http2_set_custom_header(3)](http2_set_custom_header.md)**
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# http2_get_response_code

## NAME

**http2_get_response_code** - Gets the response code

## SYNOPSIS

*void* **http2_get_response_code**(handle: *int*);

**http_get** takes one argument.

## DESCRIPTION
After performing a request, is possible to get the response code calling this function and giving the handle identifier.

## RETURN VALUE
It returns an intenger with the response code. Null on error

## EXAMPLES

**1** Get and display the response code:
```cpp
h = http2_handle();
display(h);

r = http2_get(handle:h, port:3000, item:"/vts", schema:"http");
display("response: ", r);
rc = http2_get_response_code(handle:h);
display("return code: ", rc);
```
## SEE ALSO
**[http2_delete(3)](http2_delete.md)**, **[http2_get(3)](http2_get.md)**, **[http2_close_handle(3)](http2_close_handle.md)**, **[http2_head(3)](http2_head.md)**, **[http2_handle(3)](http2_handle.md)**, **[http2_post(3)](http2_post.md)**, **[http2_put(3)](http2_put.md)**, **[http2_get_response_code(3)](http2_get_response_code.md)**, **[http2_set_custom_header(3)](http2_set_custom_header.md)**
29 changes: 29 additions & 0 deletions doc/manual/nasl/built-in-functions/http2-functions/http2_handle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# http2_handle

## NAME

**http2_handle** - Creates a handle for http requests.

## SYNOPSIS

*void* **http_handle**();

**http_handle** takes no argument.

## DESCRIPTION
Initialize a handle for performing http requests.

## RETURN VALUE
It returns an integer or NULL on error.

## EXAMPLES

**1** Get the handle identifier
```cpp
h = http2_handle();
display(h);
```
## SEE ALSO
**[http2_delete(3)](http2_delete.md)**, **[http2_get(3)](http2_get.md)**, **[http2_close_handle(3)](http2_close_handle.md)**, **[http2_head(3)](http2_head.md)**, **[http2_handle(3)](http2_handle.md)**, **[http2_post(3)](http2_post.md)**, **[http2_put(3)](http2_put.md)**, **[http2_get_response_code(3)](http2_get_response_code.md)**, **[http2_set_custom_header(3)](http2_set_custom_header.md)**
37 changes: 37 additions & 0 deletions doc/manual/nasl/built-in-functions/http2-functions/http2_head.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# http2_head

## NAME

**http2_head** - performs an HTTP2 HEAD request for the server on the port.

## SYNOPSIS

*void* **http_head**(handle: *int*, port: *int*, schema: *string*, item: *string*, data: *string*);

**http_head** takes five named arguments.

## DESCRIPTION
Performs an HTTP2 HEAD request for the server on the port. It tries to force the version HTTP2 if `https` (default) is passed as schema uses ALPN to negotiate the protocol to use.

If `http` is passed as schema, the function includes an upgrade header in the initial request to the host to allow upgrading to HTTP/2.
The arguments are port and item (the path, query, etc), schema (optional, defualt `https`) and `data` (optional).

## RETURN VALUE
It returns a string (the http response). Null on error

## EXAMPLES

**1** Get and display the formatted head request:
```cpp
h = http2_handle();
display(h);

r = http2_head(handle:h, port:3000, item:"/", schema:"http");
display("response: ", r);
rc = http2_get_response_code(handle:h);
display("return code: ", rc);
```
## SEE ALSO
**[http2_delete(3)](http2_delete.md)**, **[http2_get(3)](http2_get.md)**, **[http2_close_handle(3)](http2_close_handle.md)**, **[http2_head(3)](http2_head.md)**, **[http2_handle(3)](http2_handle.md)**, **[http2_post(3)](http2_post.md)**, **[http2_put(3)](http2_put.md)**, **[http2_get_response_code(3)](http2_get_response_code.md)**, **[http2_set_custom_header(3)](http2_set_custom_header.md)**
37 changes: 37 additions & 0 deletions doc/manual/nasl/built-in-functions/http2-functions/http2_post.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# http2_post

## NAME

**http2_post** - performs an HTTP2 POST request for the server on the port.

## SYNOPSIS

*void* **http_post**(handle: *int*, port: *int*, schema: *string*, item: *string*, data: *string*);

**http_post** takes five named arguments.

## DESCRIPTION
Performs an HTTP2 POST request for the server on the port. It tries to force the version HTTP2 if `https` (default) is passed as schema uses ALPN to negotiate the protocol to use.

If `http` is passed as schema, the function includes an upgrade header in the initial request to the host to allow upgrading to HTTP/2.
The arguments are port and item (the path, query, etc), schema (optional, defualt `https`) and `data` (optional).

## RETURN VALUE
It returns a string (the http response). Null on error

## EXAMPLES

**1** Get and display the formatted post request:
```cpp
h = http2_handle();
display(h);

r = http2_post(handle:h, port:3000, item:"/scan", schema:"http", data:"bad scan config format");
display("response: ", r);
rc = http2_get_response_code(handle:h);
display("return code: ", rc);
```
## SEE ALSO
**[http2_delete(3)](http2_delete.md)**, **[http2_get(3)](http2_get.md)**, **[http2_close_handle(3)](http2_close_handle.md)**, **[http2_head(3)](http2_head.md)**, **[http2_handle(3)](http2_handle.md)**, **[http2_post(3)](http2_post.md)**, **[http2_put(3)](http2_put.md)**, **[http2_get_response_code(3)](http2_get_response_code.md)**, **[http2_set_custom_header(3)](http2_set_custom_header.md)**
37 changes: 37 additions & 0 deletions doc/manual/nasl/built-in-functions/http2-functions/http2_put.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# http2_put

## NAME

**http2_put** - performs an HTTP2 PUT request for the server on the port.

## SYNOPSIS

*void* **http_put**(handle: *int*, port: *int*, schema: *string*, item: *string*, data: *string*);

**http_put** takes five named arguments.

## DESCRIPTION
Performs an HTTP2 PUT request for the server on the port. It tries to force the version HTTP2 if `https` (default) is passed as schema uses ALPN to negotiate the protocol to use.

If `http` is passed as schema, the function includes an upgrade header in the initial request to the host to allow upgrading to HTTP/2.
The arguments are port and item (the path, query, etc), schema (optional, defualt `https`) and `data` (optional).

## RETURN VALUE
It returns a string (the http response). Null on error

## EXAMPLES

**1** Get and display the formatted put request:
```cpp
h = http2_handle();
display(h);

r = http2_put(handle:h, port:3000, item:"/scan", schema:"http", data:"bad scan config format");
display("response: ", r);
rc = http2_get_response_code(handle:h);
display("return code: ", rc);
```
## SEE ALSO
**[http2_delete(3)](http2_delete.md)**, **[http2_get(3)](http2_get.md)**, **[http2_close_handle(3)](http2_close_handle.md)**, **[http2_head(3)](http2_head.md)**, **[http2_handle(3)](http2_handle.md)**, **[http2_post(3)](http2_post.md)**, **[http2_put(3)](http2_put.md)**, **[http2_get_response_code(3)](http2_get_response_code.md)**, **[http2_set_custom_header(3)](http2_set_custom_header.md)**
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# http2_set_custom_header

## NAME

**http2_set_custom_header** - Set a custom header element in the header

## SYNOPSIS

*void* **http_set_custom_header**(handle: *int*, header_item: *string*);

**http_set_custom_header** takes two arguments.

## DESCRIPTION
Adds a new element to initialized handle header.

## RETURN VALUE
It returns an integer or NULL on error.

## EXAMPLES

**1** Set a new element in the header
```cpp
h = http2_handle();
display(h);
http2_set_custom_header(handle: h, handle_item: "Content-Type: application/json");
```
## SEE ALSO
**[http2_delete(3)](http2_delete.md)**, **[http2_get(3)](http2_get.md)**, **[http2_close_handle(3)](http2_close_handle.md)**, **[http2_head(3)](http2_head.md)**, **[http2_handle(3)](http2_handle.md)**, **[http2_post(3)](http2_post.md)**, **[http2_put(3)](http2_put.md)**, **[http2_get_response_code(3)](http2_get_response_code.md)**, **[http2_set_custom_header(3)](http2_set_custom_header.md)**
16 changes: 16 additions & 0 deletions doc/manual/nasl/built-in-functions/http2-functions/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# HTTP2 Functions

## GENERAL

These functions are mainly used for performing HTTP2 request.

## TABLE OF CONTENT
- **[http2_handle](http2_handle.md)** - Creates a handle for http requests.
- **[http2_close_handle](http2_close_handle.md)** - Close a handle for http requests previously initialized.
- **[http2_get_response_code](http2_get_response_code.md)** - Get the http response code after performing a HTTP request.
- **[http2_set_custom_header](http2_set_custom_header.md)** - Set a custom header element in the header.
- **[http2_delete](http2_delete.md)** - performs an HTTP2 DELETE request for the server on the port.
- **[http2_get](http2_get.md)** - performs an HTTP2 DELETE request for the server on the port.
- **[http2_head](http2_head.md)** - performs an HTTP2 HEAD request for the server on the port.
- **[http2_post](http2_post.md)** - performs an HTTP2 POST request for the server on the port.
- **[http2_put](http2_put.md)** - performs an HTTP2 PUT request for the server on the port.
2 changes: 1 addition & 1 deletion nasl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ set (FILES arc4.c capture_packet.c charcnv.c exec.c genrand.c hmacmd5.c
nasl_builtin_openvas_tcp_scanner.c nasl_builtin_synscan.c
nasl_cmd_exec.c nasl_crypt_helper.c nasl_crypto2.c nasl_frame_forgery.c nasl_snmp.c nasl_ssh.c
nasl_cert.c nasl_crypto.c nasl_debug.c nasl_func.c nasl_grammar.tab.c nasl_host.c
nasl_http.c nasl_init.c nasl_lex_ctxt.c nasl_misc_funcs.c nasl_scanner_glue.c
nasl_http.c nasl_http2.c nasl_init.c nasl_lex_ctxt.c nasl_misc_funcs.c nasl_scanner_glue.c
nasl_packet_forgery.c nasl_packet_forgery_v6.c nasl_signature.c nasl_smb.c
nasl_socket.c nasl_text_utils.c nasl_tree.c nasl_var.c nasl_wmi.c
nasl_isotime.c ntlmssp.c smb_crypt.c smb_crypt2.c smb_signing.c time.c)
Expand Down
Loading

0 comments on commit fc30c99

Please sign in to comment.