Nmap Development mailing list archives

Re: payload file prototype


From: Jay Fink <jay.fink () gmail com>
Date: Thu, 18 Feb 2010 12:43:25 -0500

On Mon, Feb 15, 2010 at 9:49 PM, David Fifield <david () bamsoftware com> wrote:

I don't know what you mean by the bare value and a loop. You might have
to do some things like defining operator< on proto_port to make it fit
the interface of std::map. Once you've done that, lookup is something
like

       std::map<struct proto_port, struct payload>::iterator it;
       it = Payload.find(tmp_proto_port);
       if (it == Payload.end())
               return NULL;
       else
               return &*it;

voila - some test stuff I put together last night and beat upon at
lunch today, the only issue I have right now is *getting* the payload
back but I'm sure I'll figure it out - once that is done it becomes
the plug and chug of initializing the global map, note I cut out
includes and any gunk for readability:


using namespace std;

void fake_payload(void); // temporary til init is done
void find_payload (u8 proto, u16 dport);
static std::map<struct proto_dport, char *> payload;
static int pairmatch = 0;

struct proto_dport {
  u8  proto;
  u16 dport;

  /* Compares one protocol/destination port pair and returns result */
  bool operator<(const struct proto_dport &other) const {
    if (proto == other.proto)
     if (dport == other.dport) pairmatch = 1;
  }
};

void fake_payload (void) {
  struct proto_dport pp;
  static char example[] = "\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00";

  pp.proto = 17;
  pp.dport = 53;
  payload[pp] =  example;
}

void find_payload (u8 proto, u16 dport) {
  std::map<struct proto_dport, char *>::iterator it;
  char payload_string[4096];
  struct proto_dport pp;

  pp.proto = proto;
  pp.dport = dport;
  it = payload.find(pp);
  if (pairmatch == 1)
    printf("Match found\n");
}

/* XXX Wrapper test stuff */
const char *get_udp_payload(u16 dport, size_t *length) {
  find_payload(17, dport); /* 17 is UDP */
  return "nada for now";
}

int main(int argc, char **argv) {
  const char *payload;
  size_t payload_length;
  u8 dport = 0;

  if (argv[1]) dport = atoi(argv[1]);
  fake_payload(); /* Load up a fake payload */
  payload = get_udp_payload(dport, &payload_length);
  return 0;
}
_______________________________________________
Sent through the nmap-dev mailing list
http://cgi.insecure.org/mailman/listinfo/nmap-dev
Archived at http://seclists.org/nmap-dev/


Current thread: