Skip to content

Commit

Permalink
unix: Implement basic 'send' functions
Browse files Browse the repository at this point in the history
These compile under linux. The windows build may not work

Signed-off-by: Aaron Conole <aconole@bytheb.org>
  • Loading branch information
apconole committed Oct 30, 2015
1 parent 9f4cf2c commit c2c8482
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 4 deletions.
4 changes: 4 additions & 0 deletions options-block.h
Expand Up @@ -196,15 +196,19 @@ static inline char is_unix_stream(option_block *opts) {
}

static inline void set_unix_stream(option_block *opts) {
#ifndef __WIN32__
opts->fuzz_flag |= FUZZ_UNIX;
#endif
}

static inline char is_unix_dgram(option_block *opts) {
return opts->fuzz_flag & FUZZ_UNIX_DGRAM;
}

static inline void set_unix_dgram(option_block *opts) {
#ifndef __WIN32__
opts->fuzz_flag |= FUZZ_UNIX_DGRAM;
#endif
}

static inline char is_unix(option_block *opts) {
Expand Down
79 changes: 78 additions & 1 deletion os-abs.c
@@ -1,6 +1,6 @@
/**
* Simple Fuzz
* Copyright (c) 2009-2010, Aaron Conole <apconole@yahoo.com>
* Copyright (c) 2009-2015, Aaron Conole <apconole@yahoo.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -56,6 +56,7 @@ typedef char * caddr_t;
#include <netinet/ip.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/un.h>

#include <errno.h>
#endif
Expand Down Expand Up @@ -583,6 +584,82 @@ int os_send_udp(option_block *opts, char *str, int len)
return 0;
}

int os_send_unix_stream(option_block *opts, char *str, int len)
{
#ifdef __WIN32__
return -1;
#endif

FILE *log = stdout;
struct sockaddr_un sa_unix;
int sockfd = -1;

if(opts->fp_log)
log = opts->fp_log;

sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
if( sockfd != -1)
{
sa_unix.sun_family = AF_UNIX;
strcpy(sa_unix.sun_path, opts->host_spec);
if(connect(sockfd, &sa_unix, sizeof sa_unix) < 0)
{
close(sockfd);
fprintf(log, "[%s] error: unable to connect to unix socket [%s]\n",
get_time_as_log(), process_error());
return -1;
}

// connected - send
if( send(sockfd, str, len, 0) < 0 ){
// handle the failure case...
}

if(opts->verbosity != QUIET)
fprintf(log, "[%s] info: tx fuzz - scanning for reply.\n",
get_time_as_log());

close(sockfd);
return 0;

}
return -1;
}

int os_send_unix_dgram(option_block *opts, char *str, int len)
{
#ifdef __WIN32__
return -1;
#endif

FILE *log = stdout;
struct sockaddr_un sa_unix;
int sockfd = -1;

if(opts->fp_log)
log = opts->fp_log;

sockfd = socket(AF_UNIX, SOCK_DGRAM, 0);
if( sockfd != -1)
{
sa_unix.sun_family = AF_UNIX;
strcpy(sa_unix.sun_path, opts->host_spec);

if( sendto(sockfd, str, len, 0,
&sa_unix, sizeof sa_unix) < 0 ){
// handle the failure case...
}

if(opts->verbosity != QUIET)
fprintf(log, "[%s] info: tx fuzz - scanning for reply.\n",
get_time_as_log());

close(sockfd);
return 0;
}
return -1;
}

void *__internal_memmem(const void *hs, size_t hsl, const void *nd, size_t ndl)
{
const char *start;
Expand Down
15 changes: 13 additions & 2 deletions os-abs.h
@@ -1,6 +1,6 @@
/**
* Simple Fuzz
* Copyright (c) 2009-2010, Aaron Conole <apconole@yahoo.com>
* Copyright (c) 2009-2015, Aaron Conole <apconole@yahoo.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -59,6 +59,17 @@ extern int os_send_tcp(option_block *opts, char *req, int len);
*/
extern int os_send_udp(option_block *opts, char *req, int len);

/**
* \brief An OS Abstraction for sending datagram data
*
* os_send_unix uses a SOCK_STREAM socket.
* \param opts The options block which holds a valid dgram interface socket
* \param req A bunch of data to send
* \param len The length of the data
* \return 0 on success, <0 on failure.
*/
extern int os_send_unix_stream(option_block *opts, char *req, int len);

/**
* \brief An OS Abstraction for sending datagram data
*
Expand All @@ -68,7 +79,7 @@ extern int os_send_udp(option_block *opts, char *req, int len);
* \param len The length of the data
* \return 0 on success, <0 on failure.
*/
extern int os_send_unix(option_block *opts, char *req, int len);
extern int os_send_unix_dgram(option_block *opts, char *req, int len);

/**
* \brief There is no cross-platform standard for string replacement. Here is
Expand Down
3 changes: 2 additions & 1 deletion sfuzz.c
Expand Up @@ -114,7 +114,8 @@ void print_help()
printf("\t-t\t Wait time for reading the socket\n");
printf("\t-S\t Remote host\n");
printf("\t-p\t Port\n");
printf("\t-T|-U|-d|-u|-O TCP|UDP|unix_dgram|unix_stream|Output mode\n");
printf("\t-T|-U|-O TCP|UDP|Output mode\n");
printf("\t-d|-u unix_dgram|unix_stream (unix-alike only)\n");
printf("\t-R\t Refrain from closing connections (ie: \"leak\" them)\n");
printf("\n");
printf("\t-f\t Config File\n");
Expand Down

0 comments on commit c2c8482

Please sign in to comment.