mirror of
https://github.com/vanhauser-thc/thc-hydra.git
synced 2025-08-22 14:23:54 -07:00
增加将结果输出到redis
This commit is contained in:
parent
95e74a3ffe
commit
da0b28c119
4 changed files with 2835 additions and 2725 deletions
3
hydra.h
3
hydra.h
|
@ -177,6 +177,7 @@ typedef enum {
|
|||
FORMAT_PLAIN_TEXT,
|
||||
FORMAT_JSONV1,
|
||||
FORMAT_JSONV2,
|
||||
FORMAT_REDIS,
|
||||
FORMAT_XMLV1
|
||||
} output_format_t;
|
||||
|
||||
|
@ -211,6 +212,8 @@ typedef struct {
|
|||
char *server;
|
||||
char *service;
|
||||
char bfg;
|
||||
char *key; //redis save key
|
||||
char *map_key; //redis save map key
|
||||
} hydra_option;
|
||||
|
||||
#define _HYDRA_H
|
||||
|
|
|
@ -9,32 +9,84 @@
|
|||
#include "output-redis.h"
|
||||
|
||||
void set(const unsigned char *key, const unsigned char *value)
|
||||
{
|
||||
if (conn == NULL)
|
||||
{
|
||||
conn = redisConnect(REDIS_IP, REDIS_PORT);
|
||||
}
|
||||
if(conn != NULL && conn->err)
|
||||
{
|
||||
printf("connection error: %s\n",conn->errstr);
|
||||
}
|
||||
redisReply *reply = (redisReply*)redisCommand(conn,"set %s %s", key, value);
|
||||
freeReplyObject(reply);
|
||||
}
|
||||
|
||||
void get(char *value, const unsigned char *key)
|
||||
{
|
||||
if (conn == NULL)
|
||||
{
|
||||
conn = redisConnect(REDIS_IP, REDIS_PORT);
|
||||
}
|
||||
if(conn != NULL && conn->err)
|
||||
{
|
||||
printf("connection error: %s\n",conn->errstr);
|
||||
}
|
||||
redisReply *reply = redisCommand(conn,"get %s", key);
|
||||
sprintf(value, "%s", reply->str);
|
||||
freeReplyObject(reply);
|
||||
}
|
||||
|
||||
void lpush(const unsigned char *key, const unsigned char *value)
|
||||
{
|
||||
if (conn == NULL)
|
||||
{
|
||||
conn = redisConnect("127.0.0.1", 6379);
|
||||
}
|
||||
if(conn != NULL && conn->err)
|
||||
{
|
||||
|
||||
printf("connection error: %s\n",conn->errstr);
|
||||
}
|
||||
redisReply *reply = (redisReply*)redisCommand(conn,"set %s %s", key, value);
|
||||
freeReplyObject(reply);
|
||||
|
||||
/*reply = redisCommand(conn,"get %s", key);
|
||||
printf("%s\n",reply->str);
|
||||
freeReplyObject(reply); */
|
||||
|
||||
|
||||
if(conn != NULL && conn->err)
|
||||
{
|
||||
printf("connection error: %s\n",conn->errstr);
|
||||
}
|
||||
redisReply *reply = (redisReply*)redisCommand(conn,"lpush %s %s", key, value);
|
||||
freeReplyObject(reply);
|
||||
}
|
||||
|
||||
void key(char *key, const unsigned char *str){
|
||||
//随机种子
|
||||
srand(time(0));
|
||||
sprintf(key, "%s-%d", str, rand());
|
||||
}
|
||||
|
||||
void redis_free()
|
||||
{
|
||||
redisFree(conn);
|
||||
}
|
||||
char *replace(char *src, char *sub, char *dst)
|
||||
{
|
||||
int pos = 0;
|
||||
int offset = 0;
|
||||
int srcLen, subLen, dstLen;
|
||||
char *pRet = NULL;
|
||||
|
||||
srcLen = strlen(src);
|
||||
subLen = strlen(sub);
|
||||
dstLen = strlen(dst);
|
||||
pRet = (char *)malloc(srcLen + dstLen - subLen + 1);//(外部是否该空间)
|
||||
if (NULL != pRet)
|
||||
{
|
||||
pos = strstr(src, sub) - src;
|
||||
memcpy(pRet, src, pos);
|
||||
offset += pos;
|
||||
memcpy(pRet + offset, dst, dstLen);
|
||||
offset += dstLen;
|
||||
memcpy(pRet + offset, src + pos + subLen, srcLen - pos - subLen);
|
||||
offset += srcLen - pos - subLen;
|
||||
*(pRet + offset) = '\0';
|
||||
}
|
||||
return pRet;
|
||||
}
|
||||
/*int main()
|
||||
{
|
||||
set("a", "1");
|
||||
set("a", "1");
|
||||
return 0;
|
||||
}*/
|
||||
|
|
|
@ -1,15 +1,26 @@
|
|||
//
|
||||
// hydra-rtsp.c
|
||||
// hydra-rtsp
|
||||
// output-redis.c
|
||||
// output-redis
|
||||
//
|
||||
// Created by Javier zhukun on 03/04/18.
|
||||
// Created by zhukun on 03/04/18.
|
||||
//
|
||||
//
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
#include "lib/hiredis/hiredis.h"
|
||||
|
||||
#define REDIS_IP "127.0.0.1"
|
||||
#define REDIS_PORT 6379
|
||||
|
||||
redisContext *conn;
|
||||
|
||||
void set(const unsigned char *key, const unsigned char *value);
|
||||
void redis_free();
|
||||
void get(char *value, const unsigned char *key);
|
||||
void lpush(const unsigned char *key, const unsigned char *value);
|
||||
void key(char *map_key, const unsigned char *str);
|
||||
void redis_free();
|
||||
|
||||
char *replace(char *src, char *sub, char *dst);
|
Loading…
Add table
Add a link
Reference in a new issue