Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C 

Linux C++/C Dll injection + Code Injection Tutorial - Part Three

Main Page - https://hackforums.net/showthread.php?tid=2220892

This part we'll create the client part of our tutorial.

First copy this program and compile.

client.c
Code
#include <stdio.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <strings.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>

#define DEFAULT_PROTOCOL 0
#define PORT 50000

int main(int argc, char**argv)
{
  int clientfd;
  char recvline[BUFSIZ];
  FILE * fd = NULL;
  struct sockaddr_in servaddr;

  if ( argc != 3 )
  {
    fputs( "Usage error - a.out <IPaddress> <Filename>\n", stderr );
    exit(EXIT_FAILURE);
  }

  if (!(fd = fopen(argv[2], "r")))
  {
    fprintf(stderr, "Could not open %s\n", argv[2]);
    exit(EXIT_FAILURE);
  }

  if ((clientfd = socket(AF_INET, SOCK_STREAM, DEFAULT_PROTOCOL)) < 0)
  {
    perror("socket");
    exit(EXIT_FAILURE);
  }

  bzero(&servaddr, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_port = htons(PORT);

  if ((inet_pton(AF_INET, argv[1], &servaddr.sin_addr.s_addr)) <= 0)
  {
    fputs( "Conversion error!\n", stderr );
    exit(EXIT_FAILURE);
  }

  if ((connect(clientfd, (const struct sockaddr*)&servaddr, sizeof(servaddr))) < 0)
  {
    perror("connect");
    exit(EXIT_FAILURE);
  }

  while ( write(clientfd, recvline, fread(recvline, sizeof(char), BUFSIZ, fd)) )
  {}

  fclose(fd);
  close(clientfd);
  exit(EXIT_SUCCESS);
}

Compile line
Code
gcc client.c -Wall -ansi -pedantic -o client

And usage, we pass as arguments the IP address 127.0.0.1 and the shell script 'hello' that we prepared in step two.

Code
./client 127.0.0.1 hello

This is the simple step, creating the client. The program 'client' will only work when we complete the final step.


Possibly Related Threads...
Thread / Author Replies Views Last Post
by RowdyCatAug 20, 2025 11:58 PM 5 242 Aug 20, 2025 11:58 PM
Last Post: ▄︻デ══━一一一一━
[C] by w3w3w3Aug 3, 2021 12:38 PM 1 328 Aug 3, 2021 12:38 PM
Last Post: SIM-5058597
[C] by SecurifierJan 17, 2020 07:20 AM 12 416 Jan 17, 2020 07:20 AM
Last Post: SIM-3602340