#undef timeout_pending
@@ -122,12 +127,20 @@
int honeyd_dopoll;
int honeyd_ttl;
struct tcp_con honeyd_tmp;
+#ifdef WIN32
+int debug;
+#endif
void
usage(void)
{
fprintf(stderr,
+#ifdef WIN32
+ "WIN32 Port By Michael A. Davis (mdavis@securityprofiling.com, www.securityprofiling.com)\n"
+ "Usage: honeyd [-dPW] [-l logfile] [-i interface] [-p personalities]\n"
+#else
"Usage: honeyd [-dP] [-l logfile] [-i interface] [-p personalities]\n"
+#endif
"\t[-x xprobe] [-a assoc] [-f config] [net ...]\n");
exit(1);
}
@@ -146,8 +159,12 @@
hdr->type = SOCK_STREAM;
hdr->local = local;
con->rcv_flags = tcp->th_flags;
- con->cmd.pfd = -1;
- con->cmd.perrfd = -1;
+ con->cmd.pfd = INVALID_SOCKET;
+ con->cmd.perrfd = INVALID_SOCKET;
+#ifdef WIN32
+ con->cmd.pwritefd = INVALID_SOCKET;
+ con->cmd.IsProxyCmd = 0;
+#endif
}
void
@@ -164,9 +181,12 @@
hdr->type = SOCK_DGRAM;
hdr->local = local;
con->softerrors = 0;
- con->cmd.pfd = -1;
- con->cmd.perrfd = -1;
-
+ con->cmd.pfd = INVALID_SOCKET;
+ con->cmd.perrfd = INVALID_SOCKET;
+#ifdef WIN32
+ con->cmd.pwritefd = INVALID_SOCKET;
+ con->cmd.IsProxyCmd = 0;
+#endif
TAILQ_INIT(&con->incoming);
}
@@ -316,7 +336,12 @@
honeyd_init(char *dev, int naddresses, char **addresses)
{
struct bpf_program fcode;
+#ifndef WIN32
struct rlimit rl;
+#else
+ pcap_if_t *alldevs, *d;
+ int adapter, i;
+#endif
char filter[1024], ebuf[PCAP_ERRBUF_SIZE], *dst;
intf_t *intf;
int options, time;
@@ -330,6 +355,7 @@
memset(&honeyd_tmp, 0, sizeof(honeyd_tmp));
+#ifndef WIN32
/* Raising file descriptor limits */
if (getrlimit(RLIMIT_NOFILE, &rl) == -1)
err(1, "getrlimit");
@@ -343,6 +369,8 @@
if (setrlimit(RLIMIT_NPROC, &rl) == -1)
err(1, "setrlimit");
#endif
+#endif
+
if ((honeyd_ip = ip_open()) == NULL)
err(1, "ip_open");
@@ -352,13 +380,32 @@
if ((intf = intf_open()) == NULL)
err(1, "intf_open");
+#ifdef WIN32
+ if (pcap_findalldevs(&alldevs, ebuf) == -1)
+ errx(1, "pcap_findalldevs: %s", ebuf);
+
+ if (dev == NULL)
+ d = alldevs;
+ else {
+ adapter = atoi(dev);
+ for(i=1, d=alldevs; adapter && i <= adapter && d; i++, d=d->next);
+
+ if (d == NULL)
+ errx(1, "Unable to find adapter %d", adapter);
+ }
+ dev = d->name;
+ honeyd_ifent.intf_len = sizeof(honeyd_ifent);
+ strlcpy(honeyd_ifent.intf_name, alldevs->description, sizeof(honeyd_ifent.intf_name));
+
+#else
if (dev == NULL) {
if ((dev = pcap_lookupdev(ebuf)) == NULL)
errx(1, "pcap_lookupdev: %s", ebuf);
}
honeyd_ifent.intf_len = sizeof(honeyd_ifent);
strlcpy(honeyd_ifent.intf_name, dev, sizeof(honeyd_ifent.intf_name));
-
+#endif
+
if (intf_get(intf, &honeyd_ifent) < 0)
err(1, "intf_get");
@@ -429,7 +476,9 @@
syslog(LOG_WARNING, "calloc: %m");
return (NULL);
}
-
+#ifdef WIN32
+ con->cmd.IsProxyCmd = 0;
+#endif
honeyd_nconnects++;
honeyd_settcp(con, ip, tcp, local);
timeout_set(&con->timeout, honeyd_tcp_timeout, con);
@@ -663,7 +712,13 @@
if ((ai = cmd_proxy_getinfo(name, hdr->type, nport)) == NULL)
return (-1);
res = cmd_proxy_connect(hdr, cmd, ai, arg);
+#ifdef WIN32
+ if(ai->ai_addr)
+ free(ai->ai_addr);
+ free(ai);
+#else
freeaddrinfo(ai);
+#endif
} else
res = cmd_proxy_connect(hdr, cmd, ai, arg);
@@ -776,13 +831,22 @@
goto out;
return;
}
+#ifdef WIN32
+ argv[0] = "C:\\winnt\\system32\\cmd.exe";
+ argv[1] = "/c";
+ argv[2] = line;
+ argv[3] = NULL;
+ if (cmd_fork(hdr, cmd, tmpl, "C:\\winnt\\system32\\cmd.exe", argv, con) == -1) {
+#else
argv[0] = "/bin/sh";
argv[1] = "-c";
argv[2] = line;
argv[3] = NULL;
if (cmd_fork(hdr, cmd, tmpl, "/bin/sh", argv, con) == -1) {
+#endif
+
syslog(LOG_WARNING, "malloc %s: %m", honeyd_contoa(hdr));
goto err;
}
@@ -873,7 +937,7 @@
void
tcp_senddata(struct tcp_con *con, uint8_t flags)
{
- int space, sent;
+ unsigned int space, sent;
int needretrans = 0;
do {
@@ -1271,7 +1335,7 @@
} \
tcp_drain_payload(con, acked); \
acked += ackinc; \
- if (con->cmd_pfd == -1 && con->plen <= TCP_MAX_SEND) \
+ if (con->cmd_pfd == INVALID_SOCKET && con->plen <= TCP_MAX_SEND) \
con->sentfin = 1; \
} else if (con->sentfin) { \
if (th_ack == con->snd_una + 1) { \
@@ -1594,7 +1658,7 @@
udp = (struct udp_hdr *)(pkt + (ip->ip_hl << 2));
data = (u_char *)(pkt + (ip->ip_hl*4) + UDP_HDR_LEN);
dlen = ntohs(ip->ip_len) - (ip->ip_hl << 2) - UDP_HDR_LEN;
- if (dlen != (ntohs(udp->uh_ulen) - UDP_HDR_LEN))
+ if ((u_short)dlen != (ntohs(udp->uh_ulen) - UDP_HDR_LEN))
return;
portnum = ntohs(udp->uh_dport);
@@ -1918,7 +1982,7 @@
int delay = 0;
u_short iplen;
- if (pkthdr->caplen < honeyd_dloff + IP_HDR_LEN)
+ if (pkthdr->caplen < (unsigned int)(honeyd_dloff + IP_HDR_LEN))
return;
ip = (struct ip_hdr *)(pkt + honeyd_dloff);
@@ -2036,6 +2100,7 @@
void
child_handler(int sig)
{
+#ifndef WIN32
int s = errno;
if (signal(SIGCHLD, child_handler) == SIG_ERR) {
@@ -2047,6 +2112,7 @@
while (waitpid(-1, NULL, WNOHANG) > 0)
honeyd_nchildren--;
errno = s;
+#endif
}
int
@@ -2069,14 +2135,43 @@
char *xprobe = PATH_HONEYDDATA "/xprobe2.conf";
char *assoc = PATH_HONEYDDATA "/nmap.assoc";
char *logfile = NULL;
+#ifndef WIN32
int c, debug;
+#endif
FILE *fp;
+#ifdef WIN32
+ int c;
+ char ebuf[PCAP_ERRBUF_SIZE];
+ pcap_if_t *alldevs, *d;
+ int i;
+#endif
dev = NULL;
debug = 0;
-
+
+#ifdef WIN32
+ while ((c = getopt(argc, argv, "WVPdi:p:x:a:f:l:h?")) != -1) {
+#else
while ((c = getopt(argc, argv, "VPdi:p:x:a:f:l:h?")) != -1) {
+#endif
switch (c) {
+#ifdef WIN32
+ case 'W':
+ if (pcap_findalldevs(&alldevs, ebuf) == -1)
+ errx(1, "pcap_findalldevs: %s", ebuf);
+
+ printf("\nInterface\tDevice\t\tDescription\n-------------------------------------------\n");
+ for(i = 1, d=alldevs;d;d=d->next, i++) {
+ printf("%d %s",i, d->name);
+
+ if (d->description)
+ printf("\t%s",d->description);
+
+ printf("\n");
+ }
+ exit(1);
+ break;
+#endif /* WIN32 */
case 'V':
printf("Honeyd Version %s\n", VERSION);
exit(0);
@@ -2115,6 +2210,9 @@
if ((honeyd_rand = rand_open()) == NULL)
err(1, "rand_open");
+#ifdef WIN32
+ init_winsock();
+#endif
/* Initalize libevent but without kqueue because of bpf */
setenv("EVENT_NOKQUEUE", "yes", 0);
event_init();
@@ -2163,6 +2261,7 @@
if ((fp = fopen(PIDFILE, "w")) == NULL)
err(1, "fopen");
+#ifndef WIN32
if (!debug) {
setlogmask(LOG_UPTO(LOG_INFO));
@@ -2172,6 +2271,9 @@
}
}
fprintf(fp, "%d\n", getpid());
+#else
+ fprintf(fp, "%d\n", GetCurrentThreadId());
+#endif
fclose(fp);
chmod(PIDFILE, 0644);
@@ -2187,12 +2289,14 @@
timeout_set(&recv_ev, honeyd_poll_recv, &recv_ev);
timeout_add(&recv_ev,&tv);
}
-
+#ifndef WIN32
/* Setup signal handler */
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) {
perror("signal");
return (-1);
}
+#endif
+
if (signal(SIGINT, terminate_handler) == SIG_ERR) {
perror("signal");
return (-1);
@@ -2201,10 +2305,12 @@
perror("signal");
return (-1);
}
+#ifndef WIN32
if (signal(SIGCHLD, child_handler) == SIG_ERR) {
perror("signal");
return (-1);
}
+#endif
event_sigcb = honeyd_signal;
if (logfile != NULL)
@@ -2213,6 +2319,10 @@
event_dispatch();
syslog(LOG_ERR, "Kqueue does not recognize bpf filedescriptor.");
+
+#ifdef WIN32
+ WSACleanup();
+#endif
return (0);
}
Binary files honeyd-0.5/honeyd.exe and honeyd-0.5-win32/honeyd.exe differ
diff -urN honeyd-0.5/honeyd.h honeyd-0.5-win32/honeyd.h
--- honeyd-0.5/honeyd.h Sat Feb 15 16:01:38 2003
+++ honeyd-0.5-win32/honeyd.h Fri Mar 14 17:17:40 2003
@@ -38,7 +38,15 @@
#define timeout_initialized(ev) ((ev)->ev_flags & EVLIST_INIT)
#endif
+#ifdef WIN32
+#define PIDFILE "honeyd.pid"
+#define PATH_HONEYDDATA "."
+#define PATH_HONEYDLIB "."
+#else
#define PIDFILE "/var/run/honeyd.pid"
+#define INVALID_SOCKET -1
+#define SOCKET_ERROR -1
+#endif
#define TCP_DEFAULT_SIZE 128
#define TCP_MAX_SIZE 4096
@@ -68,7 +76,7 @@
};
#define PORT_ISOPEN(x) ((x)->status == PORT_OPEN || \
- (x)->status == PORT_OPEN || \
+ (x)->status == PORT_PROXY || \
(x)->status == PORT_SUBSYSTEM)
struct subsystem;
@@ -147,6 +155,10 @@
struct command {
pid_t pid;
+#ifdef WIN32
+ int pwritefd;
+ int IsProxyCmd;
+#endif
int pfd;
int perrfd;
@@ -314,7 +326,6 @@
struct addrinfo *cmd_proxy_getinfo(char *, int, short);
int cmd_proxy_connect(struct tuple *, struct command *, struct addrinfo *,
void *);
-
int cmd_subsystem_connect(struct tuple *hdr, struct command *cmd,
struct port *, void *arg);
int cmd_subsystem_localconnect(struct tuple *hdr, struct command *cmd,
diff -urN honeyd-0.5/honeyd.html honeyd-0.5-win32/honeyd.html
--- honeyd-0.5/honeyd.html Wed Dec 31 18:00:00 1969
+++ honeyd-0.5-win32/honeyd.html Thu Mar 13 20:52:40 2003
@@ -0,0 +1,210 @@
+
+
+
+NAME
+ honeyd - Honeypot Daemon
+
+SYNOPSIS
+ honeyd [-dPW] [-l logfile] [-p fingerprints] [-x xprobe] [-a assoc]
+ [-f file] [-i interface] [net ...]
+
+
+DESCRIPTION
+ honeyd creates virtual hosts for IP addresses matching the specified net.
+ It can simulate any TCP and UDP service. It replies to ICMP echo
+ requests. Currently, all UDP ports are closed by default and honeyd will
+ reply with an ICMP unreachable port message if the configured personality
+ permits that.
+
+ This enables a single host to claim addresses on a LAN for network simu-
+ lation. The net argument may contain multiple addresses and network
+ ranges.
+
+ In order for honeyd to receive network traffic for IP addresses that it
+ should simulate, it is necessary to either explicitly route traffic to
+ it, use proxy arp or run arpd(8) for unassigned IP addresses on a shared
+ network.
+
+ honeyd exits on an interrupt or termination signal.
+
+ The options are as follows:
+
+ -d Do not daemonize, and enable verbose debugging messages.
+
+ -P On some operating systems, it is not possible to get event noti-
+ fications for pcap via select(3). In that case, honeyd needs to
+ run in polling mode. This flag enables polling.
+
+ -W Print a list of interfaces. ** WIN32 ONLY **
+
+ -l logfile
+ Log packets and connections to the logfile specified by logfile.
+
+ -p fingerprints
+ Read nmap style fingerprints. The names defined after the token
+ are stored as personalities. The personalities can be used in
+ the configuration file to modify the behaviour of the simulated
+ TCP stack.
+
+ -x xprobe
+ Read xprobe style fingerprints. This file determines how honeyd
+ reacts to ICMP fingerprinting tools.
+
+ -a assoc
+ Read the file that associates nmap style fingerprints with xprobe
+ style fingerprints.
+
+ -f file
+ Read the configuration in file. It is possible to create host
+ templates with the configuration file that specify which servers
+ should run and which scripts should be started to simulate them.
+
+ The syntax is as follows:
+
+ config = creation | addition | binding | set | annotate | route [config]
+ creation= "create" template-name | "create" "default"
+ addition= "add" template-name proto "port" port-number action
+ binding = "bind" ip-address template-name |
+ "clone" template-name template-name
+ set = "set" template-name "default" proto "action" action |
+ "set" template-name "personality" personality-name |
+ "set" template-name "personality" "random"
+ "set" template-name "subsystem" cmd-string
+ "set" template-name "uptime" seconds
+ "set" template-name "droprate" "in" percent
+ "set" template-name "uid" number ["gid" number]
+ "set" ip-address "uptime" seconds
+ annotate= "annotate" personality-name [no] finscan |
+ "annotate" personality-name "fragment" ("drop" | "old" | "new")
+ route = "route" "entry" ipaddr |
+ "route" ipaddr "link" ipnetwork |
+ "route" ipaddr "add" "net" ipnetwork ipaddr ["latency" number"ms"] ["loss" percent]
+ proto = "tcp" | "udp" | "icmp"
+ action = "block" | "open" | "reset" | cmd-string | "proxy" ipaddr":"port
+
+ The cmd-string and the personality-name are arbitrary strings
+ enclosed with quotation marks. Variable expansion on the tokens
+ $ipsrc, $ipdst, $sport and $dport is performed when executing the
+ command string or when resolving the proxy address. Addition-
+ ally, the environment variables HONEYD_IP_SRC, HONEYD_IP_DST,
+ HONEYD_DST_PORT HONEYD_SRC_PORT and HONEYD_PERSONALITY are avail-
+ able, too.
+
+ If an IP address is not bound to a template, the actions speci-
+ fied in the default template are executed.
+
+ Personalities need to be annotated before they are assigned to a
+ template or an IP address.
+
+ The default fragment policy is to accept fragment and resolve
+ overlaps in favor of old data. If the personality returns TCP
+ timestamps, the default uptime is a randomly chosen between zero
+ and twenty days.
+
+ The special include directive may be used to include other con-
+ figuration files, for example to keep all personality annotations
+ separate from the main configuration file.
+
+ -i interface
+ Listen on interface.
+
+ net The IP address or network (specified in CIDR notation) or IP
+ address ranges to claim (e.g. ``10.0.0.3'', ``10.0.0.0/16'' or
+ ``10.0.0.5-10.0.0.15''). If unspecified, honeyd will attempt to
+ claim any IP address it sees traffic for.
+
+
+
+ROUTING TOPOLOGY
+ honeyd supports the creation of a complete network topology including
+ routing. In order to enable the simulation of a network topology, a
+ router entry point has to be configured with
+
+ route entry <IP address>
+
+ Every route add net directive creates the specified gateway as a new
+ router. The virtual machines that can be directly accessed by a router
+ are defined as network range in the route link command.
+
+
+ set template subsystem "/usr/sbin/httpd"
+
+ and are started as a separate process for every bound template. Applica-
+ tions started as a honeyd subsystem need to be dynamically linked in
+ order to work under honeyd.
+
+
+
+LOGGING
+ Honeyd has two different logging modes. The syslog facility is used to
+ log connection establishment and termination including other relevant
+ packet events.
+
+ Services started by honeyd can cause the daemon to log data by sending
+ information to stderr.
+
+ The second way of logging network activity is by using the -l flag. This
+ causes honeyd to log all received packets in a human readable format.
+ For UDP and TCP connections, honeyd logs the start and end of a flow
+ including the amount of data transfered.
+
+ For logging any other information, it is suggested to run a separate
+ intrusion detection system.
+
+
+
+EXAMPLES
+ A sample configuration file looks as follows:
+
+ # Example of a simple host template and its binding
+ include annotations
+ create template
+ set template personality "OpenBSD 2.6-2.7"
+ add template tcp port 80 "sh scripts/web.sh"
+ add template tcp port 22 "sh scripts/test.sh $ipsrc $dport"
+ add template udp port 53 proxy yournameserver:53
+ set template default tcp action reset
+ set template uid 32767 gid 32767
+
+ bind 10.11.69.2 template
+ set 10.11.69.2 uptime 1327650
+
+ A simple example of a routing topology:
+
+ route entry 10.0.0.1
+ route 10.0.0.1 link 10.2.0.0/24
+ route 10.0.0.1 add net 10.2.1.0/24 10.2.0.10 latency 10ms loss 3.4
+ route 10.2.0.10 link 10.2.1.0/24
+
+
+
+FILES
+ /var/run/honeyd.pid The PID of the current daemon.
+
+ {prefix}/lib/honeyd/libhoneyd.so A shared library that can be
+ preloaded to virtualize applications
+ within honeyd.
+
+ {prefix}/share/honeyd/nmap.assoc An association file to match xprobe2
+ fingerprints against nmap.
+
+ {prefix}/share/honeyd/nmap.prints Nmap fingerprints used by honeyd to
+ impersonate operating system stacks.
+
+ {prefix}/share/honeyd/xprobe2.conf Xprobe fingerprints used by honeyd to
+ impersonsate the ICMP section of
+ operating system stacks.
+
+
+
+AUTHORS
+ Niels Provos <provos@citi.umich.edu>
+ WIN32 Port by Michael A. Davis <mdavis@securityprofiling.com>
+
+
+
+Man(1) output converted with
+man2html
+
+
+
diff -urN honeyd-0.5/honeyd.pid honeyd-0.5-win32/honeyd.pid
--- honeyd-0.5/honeyd.pid Wed Dec 31 18:00:00 1969
+++ honeyd-0.5-win32/honeyd.pid Fri Mar 14 18:09:56 2003
@@ -0,0 +1 @@
+1716
diff -urN honeyd-0.5/ipfrag.c honeyd-0.5-win32/ipfrag.c
--- honeyd-0.5/ipfrag.c Wed Apr 17 11:36:24 2002
+++ honeyd-0.5-win32/ipfrag.c Thu Mar 13 19:29:08 2003
@@ -28,18 +28,24 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include
#include
#include "config.h"
+#ifdef WIN32
+#include
+#else
+#include
+#include
+#include
+#include
+#endif
+
#ifdef HAVE_SYS_TIME_H
#include
#endif
-#include
#include
#include
-#include
#include
#include
@@ -48,7 +54,6 @@
#include
#include
#include
-#include
#include
#include
@@ -241,12 +246,12 @@
if (prev && prev->off + prev->len > off) {
overlap = prev->off + prev->len - off;
- if (overlap > len) {
+ if (overlap >= len) {
if (fragq->fragp == FRAG_NEW) {
u_char *odata = prev->data + off - prev->off;
memcpy(odata, ent->data, len);
}
- goto drop_fragment;
+ goto free_fragment;
}
if (fragq->fragp == FRAG_OLD) {
@@ -316,6 +321,7 @@
drop_fragment:
TAILQ_REMOVE(&fragq->fraglist, ent, next);
+ free_fragment:
ip_fragent_free(ent);
return (0);
}
diff -urN honeyd-0.5/lex.c honeyd-0.5-win32/lex.c
--- honeyd-0.5/lex.c Wed Feb 12 20:03:48 2003
+++ honeyd-0.5-win32/lex.c Thu Mar 13 16:27:00 2003
@@ -516,7 +516,11 @@
#include "config.h"
#include
+#ifdef WIN32
+#include
+#else
#include
+#endif
#ifdef HAVE_SYS_TIME_H
#include
#endif
diff -urN honeyd-0.5/lex.l honeyd-0.5-win32/lex.l
--- honeyd-0.5/lex.l Wed Feb 12 19:58:27 2003
+++ honeyd-0.5-win32/lex.l Thu Mar 13 16:27:30 2003
@@ -36,7 +36,9 @@
#include "config.h"
#include
+#ifndef WIN32
#include
+#endif
#ifdef HAVE_SYS_TIME_H
#include
#endif
diff -urN honeyd-0.5/log.c honeyd-0.5-win32/log.c
--- honeyd-0.5/log.c Sat Feb 15 16:07:37 2003
+++ honeyd-0.5-win32/log.c Thu Mar 13 16:31:28 2003
@@ -27,8 +27,6 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-
-#include
#include
#include "config.h"
@@ -47,7 +45,13 @@
#include
#include
#include
+#ifdef WIN32
+#include "misc.h"
+typedef unsigned short ushort;
+#else
+#include
#include
+#endif
#ifdef HAVE_TIME_H
#include
#endif
diff -urN honeyd-0.5/parse.c honeyd-0.5-win32/parse.c
--- honeyd-0.5/parse.c Wed Feb 12 21:48:21 2003
+++ honeyd-0.5-win32/parse.c Thu Mar 13 19:51:44 2003
@@ -28,7 +28,9 @@
# define PROXY 279
# define UPTIME 280
# define DROPRATE 281
+#ifndef WIN32
# define IN 282
+#endif
# define UID 283
# define GID 284
# define ROUTE 285
@@ -71,6 +73,10 @@
#include "personality.h"
#include "router.h"
+#ifdef WIN32
+#undef IN
+# define IN 282
+#endif
int yylex(void);
int yyparse(void);
int yyerror(char *, ...);
@@ -1074,11 +1080,15 @@
case 12:
#line 142 "parse.y"
{
+#ifdef WIN32
+ yyerror("subsystems are not supported in the win32 version.");
+#else
yyvsp[0].string[strlen(yyvsp[0].string) - 1] = '\0';
if (yyvsp[-2].tmpl != NULL && template_subsystem(yyvsp[-2].tmpl, yyvsp[0].string+1) == -1)
yyerror("Can not add subsystem \"%s\" to template \"%s\"",
yyvsp[0].string+1, yyvsp[-2].tmpl != NULL ? yyvsp[-2].tmpl->name : "");
free(yyvsp[0].string);
+#endif
}
break;
case 13:
diff -urN honeyd-0.5/parse.h honeyd-0.5-win32/parse.h
--- honeyd-0.5/parse.h Wed Feb 12 19:58:56 2003
+++ honeyd-0.5-win32/parse.h Thu Mar 13 16:28:14 2003
@@ -40,6 +40,9 @@
# define PROXY 279
# define UPTIME 280
# define DROPRATE 281
+#ifdef WIN32
+#undef IN
+#endif
# define IN 282
# define UID 283
# define GID 284
diff -urN honeyd-0.5/personality.c honeyd-0.5-win32/personality.c
--- honeyd-0.5/personality.c Sat Jan 25 14:42:17 2003
+++ honeyd-0.5-win32/personality.c Thu Mar 13 16:35:54 2003
@@ -28,7 +28,6 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include
#include
#include "config.h"
@@ -36,11 +35,18 @@
#ifdef HAVE_SYS_TIME_H
#include
#endif
+#ifdef WIN32
+#include
+#include "misc.h"
+#else
+#include
#include
+#include
+#include
+#endif
#include
#include
#include
-#include
#include
#include
@@ -49,7 +55,6 @@
#include
#include
#include
-#include
#include
#include
@@ -65,7 +70,7 @@
/* ET - Moved SPLAY_HEAD to personality.h so xprobe_assoc.c could use it. */
int npersons;
/* ET - global from honeyd.c */
-struct personate person_drop = {};
+struct personate person_drop = {0};
SPLAY_GENERATE(perstree, personality, node, perscompare);
@@ -1087,7 +1092,7 @@
} else if (strncasecmp(p2, "TOS=", 4) == 0) {
p2 += 4;
- test->tos = strtoul(p2, &end, 16);
+ test->tos = (uint8_t)strtoul(p2, &end, 16);
if (end == NULL || *end != '\0')
return (-1);
} else if (strncasecmp(p2, "IPLEN=", 6) == 0) {
diff -urN honeyd-0.5/router.c honeyd-0.5-win32/router.c
--- honeyd-0.5/router.c Tue Sep 17 13:47:26 2002
+++ honeyd-0.5-win32/router.c Thu Mar 13 16:36:16 2003
@@ -29,7 +29,10 @@
*/
#include
+#ifndef WIN32
#include
+#include
+#endif
#include "config.h"
@@ -41,7 +44,6 @@
#include
#include
#include
-#include
#include
#include
diff -urN honeyd-0.5/scripts/router-telnet.pl honeyd-0.5-win32/scripts/router-telnet.pl
--- honeyd-0.5/scripts/router-telnet.pl Wed Apr 17 21:21:18 2002
+++ honeyd-0.5-win32/scripts/router-telnet.pl Fri Mar 14 11:31:58 2003
@@ -33,7 +33,7 @@
";
syswrite STDOUT, $string;
-
+open(O, ">C:\\fff");
$count = 0;
while ($count < 3) {
do {
@@ -70,6 +70,7 @@
$finished = 0;
do {
$nread = sysread STDIN, $buffer, 1;
+ print O "RET: " . $nread . " BUF: " . $buffer . "\n";
die unless $nread;
if (ord($buffer) == 0) {
; #ignore
diff -urN honeyd-0.5/subsystem.c honeyd-0.5-win32/subsystem.c
--- honeyd-0.5/subsystem.c Sat Feb 15 16:09:07 2003
+++ honeyd-0.5-win32/subsystem.c Thu Mar 13 21:06:14 2003
@@ -28,7 +28,6 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include
#include
#ifdef HAVE_CONFIG_H
@@ -41,7 +40,10 @@
#include
#include
+#ifndef WIN32
+#include
#include
+#endif
#include
#include
#include
diff -urN honeyd-0.5/tcp.c honeyd-0.5-win32/tcp.c
--- honeyd-0.5/tcp.c Mon Feb 10 23:41:49 2003
+++ honeyd-0.5-win32/tcp.c Fri Mar 14 19:05:48 2003
@@ -29,16 +29,22 @@
*/
#include
-#include
-#include "config.h"
+#include "config.h"
+#ifdef HAVE_SYS_TIME_H
+#include
+#endif
+#ifndef WIN32
+#include
+#include
#include
+#include
+#include
+#endif
#include
#include
#include
-#include
-#include
#include
#include
@@ -47,7 +53,6 @@
#include
#include
#include
-#include
#include
#include
@@ -105,9 +110,9 @@
int
tcp_add_readbuf(struct tcp_con *con, u_char *dat, u_int datlen)
{
- int space;
+ unsigned int space;
- if (con->cmd_pfd == -1)
+ if (con->cmd_pfd == INVALID_SOCKET)
return (datlen);
space = con->rsize - con->rlen;
@@ -134,9 +139,30 @@
int nread;
struct command *cmd = &con->cmd;
+#ifdef WIN32
+ BOOL fRet;
+
+ fRet = PeekNamedPipe((HANDLE)fd, NULL, 0, NULL, &nread, NULL);
+ if(!fRet) {
+ cmd_free(&con->cmd);
+ return;
+ }
+
+ if(!nread) {
+ event_add(&cmd->peread, NULL);
+ return;
+ }
+
+ ReadFile((HANDLE)fd, line, sizeof(line), &nread, NULL);
+#else
nread = read(fd, line, sizeof(line));
+#endif
+#ifdef WIN32
+ if(GetLastError() != ERROR_NO_DATA && !nread) {
+#else
if (nread <= 0) {
+#endif
if (cmd->fdwantclose) {
/* Stdin is already closed */
cmd_free(&con->cmd);
@@ -164,19 +190,46 @@
struct tcp_con *con = arg;
int len, space;
struct command *cmd = &con->cmd;
-
+#ifdef WIN32
+ BOOL fRet;
+#endif
space = con->psize - con->plen;
if (space <= 0)
return;
+#ifdef WIN32
+ if(!cmd->IsProxyCmd) {
+ fRet = PeekNamedPipe((HANDLE)fd, NULL, 0, NULL, &len, NULL);
+ if(!fRet) {
+ cmd_free(&con->cmd);
+ return;
+ }
+
+ if(!len)
+ goto again;
+ ReadFile((HANDLE)fd, con->payload + con->plen, space, &len, NULL);
+ } else {
+ len = recv(cmd->pfd, con->payload + con->plen, space, 0);
+ if(len == SOCKET_ERROR)
+ len = 0;
+ }
+
+ if(GetLastError() != ERROR_NO_DATA && !len) {
+#else
len = read(fd, con->payload + con->plen, space);
- if (len == -1) {
+
+ if (len == SOCKET_ERROR) {
+#endif
+#ifdef WIN32
+ if (errno == EINTR || errno == EAGAIN || GetLastError() == ERROR_NO_DATA || WSAGetLastError() == WSAEWOULDBLOCK)
+#else
if (errno == EINTR || errno == EAGAIN)
+#endif
goto again;
cmd_free(&con->cmd);
return;
} else if (len == 0) {
- if (cmd->perrfd != -1 && !cmd->fdwantclose) {
+ if (cmd->perrfd != INVALID_SOCKET && !cmd->fdwantclose) {
cmd->fdwantclose = 1;
return;
}
@@ -202,11 +255,31 @@
{
struct tcp_con *con = arg;
int len;
-
+
+#ifdef WIN32
+ BOOL fRet;
+ if(con->cmd.IsProxyCmd) {
+ len = send(con->cmd.pfd, con->readbuf, con->rlen, 0);
+
+ if(len == SOCKET_ERROR)
+ fRet = FALSE;
+ else
+ fRet = TRUE;
+ } else {
+ fRet = WriteFile((HANDLE)fd, con->readbuf, con->rlen, &len, NULL);
+ }
+
+ if(!fRet) {
+#else
len = write(fd, con->readbuf, con->rlen);
- if (len == -1) {
+ if (len == SOCKET_ERROR) {
+#endif
+#ifdef WIN32
+ if (errno == EINTR || errno == EAGAIN || WSAGetLastError() == WSAEWOULDBLOCK)
+#else
if (errno == EINTR || errno == EAGAIN)
+#endif
goto again;
cmd_free(&con->cmd);
return;
@@ -236,7 +309,11 @@
goto out;
/* Check if the connection completed */
+#ifdef WIN32
+ if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (char *)&error, &errsz) == SOCKET_ERROR) {
+#else
if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &errsz) == -1) {
+#endif
warn("%s: getsockopt for %d", __FUNCTION__, fd);
goto out;
}
diff -urN honeyd-0.5/udp.c honeyd-0.5-win32/udp.c
--- honeyd-0.5/udp.c Thu Feb 13 15:49:39 2003
+++ honeyd-0.5-win32/udp.c Fri Mar 14 19:05:46 2003
@@ -29,16 +29,21 @@
*/
#include
-#include
#include "config.h"
-
+#ifdef HAVE_SYS_TIME_H
+#include
+#endif
+#ifndef WIN32
+#include
#include
+#include
+#include
+#include
+#endif
#include
#include
#include
-#include
-#include
#include
#include
@@ -47,7 +52,6 @@
#include
#include
#include
-#include