Skip to content

Instantly share code, notes, and snippets.

@farukyildiz
Created July 5, 2021 11:57
Show Gist options
  • Save farukyildiz/17149d07731dcaa1e89ba789d4b68ca6 to your computer and use it in GitHub Desktop.
Save farukyildiz/17149d07731dcaa1e89ba789d4b68ca6 to your computer and use it in GitHub Desktop.
Pf ioctl kill states DIOCKILLSTATES
#define IF_NAMESIZE 16
#define IFNAMSIZ IF_NAMESIZE
#define MAXPATHLEN 1024
#define PF_TABLE_NAME_SIZE 32
#define TH_SYN 0x02
#define TH_ACK 0x10
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/types.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <net/if.h>
#include <net/pfvar.h>
#include <arpa/inet.h>
#include <err.h>
#include <errno.h>
#ifdef __FreeBSD__
#include <inttypes.h>
#endif
#include <login_cap.h>
#include <pwd.h>
#include <grp.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <assert.h>
#include <errno.h>
#include <err.h>
int main()
{
printf("\n === started === \n");
printf("\n");
dev = open("/dev/pf", O_RDWR);
if (dev == -1)
err(1, "open /dev/pf");
struct pfioc_state_kill psk;
struct pf_addr target, target_dst;
memset(&psk, 0, sizeof(psk));
memset(&target, 0, sizeof(target));
memset(&target_dst, 0, sizeof(target_dst));
syslog(LOG_ERR, "inet_pton(%s) set", "192.168.1.41");
if (inet_pton(AF_INET, "192.168.1.41", &target.v4) == 1) {
psk.psk_af = AF_INET;
}
else {
syslog(LOG_ERR, "inet_pton(%s) failed", "192.168.1.41");
}
syslog(LOG_ERR, "inet_pton(%s) set", "192.168.1.100");
if (inet_pton(AF_INET, "192.168.1.100", &target_dst.v4) == 1) {
psk.psk_af = AF_INET;
}
else {
syslog(LOG_ERR, "inet_pton(%s) failed", "192.168.1.100");
}
memcpy(&psk.psk_src.addr.v.a.addr, &target,
sizeof(psk.psk_src.addr.v.a.addr));
memset(&psk.psk_src.addr.v.a.mask, 0xff,
sizeof(psk.psk_src.addr.v.a.mask));
memset(&psk.psk_src, 0, sizeof(psk.psk_src));
memcpy(&psk.psk_dst.addr.v.a.addr, &target_dst,
sizeof(psk.psk_dst.addr.v.a.addr));
memset(&psk.psk_dst.addr.v.a.mask, 0xff,
sizeof(psk.psk_dst.addr.v.a.mask));
if (ioctl(dev, DIOCKILLSTATES, &psk))
syslog(LOG_ERR, "DIOCKILLSTATES failed (%m)");
close(dev);
printf("\n === finally === \n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment