iagox86 / dnscat2

BSD 3-Clause "New" or "Revised" License
3.43k stars 601 forks source link

make --> snprintf error #63

Closed Swiffers closed 9 years ago

Swiffers commented 9 years ago
cc --std=c99 -I. -Wall -D_DEFAULT_SOURCE -fstack-protector-all -Wformat -Wformat-security -D_POSIX_SOURCE -g -DTESTMEMORY -Werror -O0   -c -o controller/packet.o controller/packet.c

controller/packet.c:394:5: error: implicitly declaring library function 'snprintf' with type 'int (char *, unsigned long, const char *, ...)' [-Werror]

snprintf(ret, 1024, "Type = SYN :: [0x%04x] session = 0x%04x, seq = 0x%04x, options = 0x%04x", packet->packet_id, packet->session_id, packet->body.syn.seq, packet->body.syn.options);

controller/packet.c:394:5: note: include the header <stdio.h> or explicitly provide a declaration for 'snprintf'
iagox86 commented 9 years ago

Which OS? On 15 Sep 2015 5:20 am, "Swiffers" notifications@github.com wrote:

cc --std=c99 -I. -Wall -D_DEFAULT_SOURCE -fstack-protector-all -Wformat -Wformat-security -D_POSIX_SOURCE -g -DTESTMEMORY -Werror -O0 -c -o controller/packet.o controller/packet.c controller/packet.c:394:5: error: implicitly declaring library function 'snprintf' with type 'int (char , unsigned long, const char , ...)' [-Werror] snprintf(ret, 1024, "Type = SYN :: [0x%04x] session = 0x%04x, seq = 0x%04x, options = 0x%04x", packet->packet_id, packet->session_id, packet->body.syn.seq, packet->body.syn.options); ^ controller/packet.c:394:5: note: include the header or explicitly provide a declaration for 'snprintf' 1 error generated.

— Reply to this email directly or view it on GitHub https://github.com/iagox86/dnscat2/issues/63.

Swiffers commented 9 years ago
iagox86 commented 9 years ago

Ah, I've had a similar problem in OS X before. I think I can fix it!

On Wed, Sep 16, 2015 at 12:04 AM, Swiffers notifications@github.com wrote:

  • Mac with OS X El Capitan.
  • gcc --version
    • Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
    • Apple LLVM version 7.0.0 (clang-700.0.72)
    • Target: x86_64-apple-darwin15.0.0
    • Thread model: posix

— Reply to this email directly or view it on GitHub https://github.com/iagox86/dnscat2/issues/63#issuecomment-140649963.

iagox86 commented 9 years ago

Interestingly, at the top of that function, I specifically don't include the header for Apple:

#ifndef __APPLE__
int snprintf(char *STR, size_t SIZE, const char *FORMAT, ...);
#endif

But I didn't note why, just that it's required on Cygwin! I can't find a bug for it, either. Can you try applying this patch to see if it fixes the problem, or if it causes a new problem?

diff --git a/client/controller/packet.c b/client/controller/packet.c
index 4aa0981..45966d6 100644
--- a/client/controller/packet.c
+++ b/client/controller/packet.c
@@ -20,11 +20,8 @@

 #include "packet.h"

-/* Header for snprintf(), since cygwin doesn't expose it on c89
- * programs. */
-#ifndef __APPLE__
+/* Not every OS defines snprintf(), so make sure it's defined. */
 int snprintf(char *STR, size_t SIZE, const char *FORMAT, ...);
-#endif

 packet_t *packet_parse(uint8_t *data, size_t length, options_t options)
 {

There might be an easier way, but you can put that into a file called patch.diff and run "patch -p1 < patch.diff" on it.

Let me know if it works! If so, I'll just push it and see if that breaks other OS X people. :)

Ultimately, I wonder if I can get rid of snprintf() altogether.. it works differently on Windows, OS X, and Linux in many ways...

Ron

Swiffers commented 9 years ago

Hi Ron,

Thanks for those very verbose informations, I commented the #ifndef Apple, and this patch is working well for packet.c .

But i end up with a new error on tcp.c :

libs/tcp.c:126:35: error: use of undeclared identifier 'INADDR_NONE'
  if(serv_addr.sin_addr.s_addr == INADDR_NONE)
                                  ^
1 error generated.
make: *** [libs/tcp.o] Error 1
iagox86 commented 9 years ago

Well, progress! :)

I found somebody else who reported the same bug in miniupnp.. apparently this patch fixed it for them, can you give it a shot?

$ git diff libs/tcp.c
diff --git a/client/libs/tcp.c b/client/libs/tcp.c
index 1bafd57..29c88a1 100644
--- a/client/libs/tcp.c
+++ b/client/libs/tcp.c
@@ -16,6 +16,7 @@
 #include <unistd.h>
 #include <arpa/inet.h>
 #include <netinet/in.h>
+#include <sys/param.h>
 #include <sys/socket.h>
 #include <sys/types.h>
 #endif
Swiffers commented 9 years ago

The bug seems to be the same in udp.c

I was able to debug following those informations : http://www.squid-cache.org/mail-archive/squid-users/199609/0348.html

I added this in both tcp.c & udp.c

#ifndef INADDR_NONE
#define INADDR_NONE ((in_addr_t) -1)
#endif
*** dnscat successfully compiled
*** Debug build complete
iagox86 commented 9 years ago

Ah, cool! Can you check if #include <sys/param.h> helps? If not, I'll throw that code into types.c and make sure it doesn't break Linux/win32 compilation

On Wed, Sep 16, 2015 at 12:50 PM, Swiffers notifications@github.com wrote:

The bug seems to be the same in udp.c

I was able to debug following those informations : http://www.squid-cache.org/mail-archive/squid-users/199609/0348.html

I added this in both tcp.c & udp.c

ifndef INADDR_NONE

define INADDR_NONE ((in_addr_t) -1)

endif

— Reply to this email directly or view it on GitHub https://github.com/iagox86/dnscat2/issues/63#issuecomment-140867705.

Swiffers commented 9 years ago

I just tried with

#include <sys/param.h>

But it's throwing the same error :

libs/tcp.c:128:35: error: use of undeclared identifier 'INADDR_NONE'

If i can help, ask me anything else.. i'll be happy to help Cheers ! :)

iagox86 commented 9 years ago

Cool!

Once you add that define in a place where tcp.c and udp.c can see it, you can compile?

On Wed, Sep 16, 2015 at 12:55 PM, Swiffers notifications@github.com wrote:

I just tried with

include <sys/param.h>

But it's throwing the same error :

libs/tcp.c:128:35: error: use of undeclared identifier 'INADDR_NONE'

Cheers ! :)

— Reply to this email directly or view it on GitHub https://github.com/iagox86/dnscat2/issues/63#issuecomment-140868852.

Swiffers commented 9 years ago

Yes, compile is working perfectly !

*** dnscat successfully compiled
*** Debug build complete
iagox86 commented 9 years ago

Great! Here's the full patch for both issues from today, can you apply this to a fresh checkout to make doubly sure before I commit?

$ git diff
diff --git a/client/controller/packet.c b/client/controller/packet.c
index 4aa0981..45966d6 100644
--- a/client/controller/packet.c
+++ b/client/controller/packet.c
@@ -20,11 +20,8 @@

 #include "packet.h"

-/* Header for snprintf(), since cygwin doesn't expose it on c89
- * programs. */
-#ifndef __APPLE__
+/* Not every OS defines snprintf(), so make sure it's defined. */
 int snprintf(char *STR, size_t SIZE, const char *FORMAT, ...);
-#endif

 packet_t *packet_parse(uint8_t *data, size_t length, options_t options)
 {
diff --git a/client/libs/types.h b/client/libs/types.h
index ead546d..0048260 100644
--- a/client/libs/types.h
+++ b/client/libs/types.h
@@ -30,6 +30,13 @@ typedef _W64 unsigned int   ssize_t;
 #define _SSIZE_T_DEFINED
 #endif

+/* OS X doesn't seem to have INADDR_NONE defined in all cases. */
+/* If this causes a compile error on some system, try putting "#ifdef __APPLE__"
+ * around it. */
+#ifndef INADDR_NONE
+#define INADDR_NONE ((in_addr_t) -1)
+#endif
+
 #else
 #include <stdint.h>
 #endif
iagox86 commented 9 years ago

Actually, I just went ahead and committed.. I'm fairly confident that I got it right. Please give it a shot and let me know if I messed anything up. :)

Swiffers commented 9 years ago

hmm, so i removed the modification from tcp & udp.c ; Added in type.h

#ifndef INADDR_NONE
#define INADDR_NONE ((in_addr_t) -1)
#endif

But that throw the same error

use of undeclared identifier 'INADDR_NONE'
iagox86 commented 9 years ago

Hmm, both tcp.h and udp.h include type.h. I wonder what's wrong? Do you have the same problem with the patch I just committed?

Swiffers commented 9 years ago

Yes, just downloaded & make; But still the same error.

iagox86 commented 9 years ago

Weird!

Can you get things into a state that works for you (even if it's putting it in both udp.h and tcp.h) and send me a patch or pull request? It's hard to write a decent patch without a box to test on. :)

On Wed, Sep 16, 2015 at 1:09 PM, Swiffers notifications@github.com wrote:

Yes, just downloaded & make; But still the same error.

— Reply to this email directly or view it on GitHub https://github.com/iagox86/dnscat2/issues/63#issuecomment-140871775.

Swiffers commented 9 years ago

Sure, i'm on 3G network, give me 5 minutes :)

iagox86 commented 9 years ago

Haha, no rush! I'm at work, so I can't really commit any real time for a couple hours, but a quick patch or PR are easy :)

On Wed, Sep 16, 2015 at 1:15 PM, Swiffers notifications@github.com wrote:

Sure, i'm on 3G network, give me 5 minutes :)

— Reply to this email directly or view it on GitHub https://github.com/iagox86/dnscat2/issues/63#issuecomment-140873410.

iagox86 commented 9 years ago

Oh hey, I just realized that the #ifdef I had was inside a "#ifdef WIN32" block, that's why it didn't work!

Can you give the latest HEAD version a shot?

On Wed, Sep 16, 2015 at 1:16 PM, Ron Bowes ron@skullsecurity.net wrote:

Haha, no rush! I'm at work, so I can't really commit any real time for a couple hours, but a quick patch or PR are easy :)

On Wed, Sep 16, 2015 at 1:15 PM, Swiffers notifications@github.com wrote:

Sure, i'm on 3G network, give me 5 minutes :)

— Reply to this email directly or view it on GitHub https://github.com/iagox86/dnscat2/issues/63#issuecomment-140873410.

Swiffers commented 9 years ago

Oh right ! Works perfectly with the latest version ;)

iagox86 commented 9 years ago

Great! :)

On Wed, Sep 16, 2015 at 2:06 PM, Swiffers notifications@github.com wrote:

Oh right ! Works perfectly with the latest version ;)

— Reply to this email directly or view it on GitHub https://github.com/iagox86/dnscat2/issues/63#issuecomment-140894986.

Swiffers commented 9 years ago

Thanks for your efficient help!

iagox86 commented 9 years ago

No problem! Thanks for your report! Maybe I should buy a Macbook.. :)

On Wed, Sep 16, 2015 at 2:28 PM, Swiffers notifications@github.com wrote:

Thanks for your efficient help.

— Reply to this email directly or view it on GitHub https://github.com/iagox86/dnscat2/issues/63#issuecomment-140899886.