picon
picon copied to clipboard
"unresolved external function" on RespberryPi
Hi,
I'm running picon on a RespberryPi, and I tried a simple example, the code is as follows.
#include <unistd.h>
#include <stdio.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <string.h>
#include <fcntl.h>
void vulnerable(char *arg) {
char buff[100];
printf("%p\n", &buff[0]);
strcpy(buff, arg);
}
int main(int argc, char const *argv[])
{
int server_fd, new_socket, valread;
struct sockaddr_in address;
int opt = 1, i = 0;
int addrlen = sizeof(address);
char recv_msg[1024] = {0};
int port_number;
// Opt users for entering a port number
printf("Enter server port number: ");
scanf("%d", &port_number);
// let's start the server with socket programming
// Creating socket file descriptor
if ((server_fd = socket(AF_INET, SOCK_STREAM, 0)) == 0)
{
perror("socket failed");
exit(EXIT_FAILURE);
}
// Any address that is supported by internet protocol
address.sin_family = AF_INET;
// accept any type of address (hostname/IPv4/IPv6)
address.sin_addr.s_addr = INADDR_ANY;
// convert integer values to network byte order
address.sin_port = htons(port_number);
// Binding the port address with hostname or IP address
if (bind(server_fd, (struct sockaddr *)&address, sizeof(address))<0)
{
perror("bind port with the address has been failed");
exit(EXIT_FAILURE);
}
// listen for connection requests of clients
if (listen(server_fd, 1) < 0)
{
perror("listen");
exit(EXIT_FAILURE);
}
// Server will keep accepting connection requests until stopped forcefully
while(1)
{
if ((new_socket = accept(server_fd, (struct sockaddr *)&address,
(socklen_t*)&addrlen))<0)
{
perror("Failed to accept a connection");
exit(EXIT_FAILURE);
}
// read a new socket message of any size
read( new_socket, recv_msg, sizeof(recv_msg));
// Pass the input to the vulnerable function
vulnerable(recv_msg);
}
return 0;
}
but I get an error like this
[debug] [monitor] forking
[debug] [monitor] waiting for new module
[debug] [monitor] waiting for loading packet
[debug] [ client] exec
[debug] [ client] sending loading packet (size = 5)
[debug] [ client] waiting for monitor to loading packet
[debug] [monitor] received CFI_LOADING_MODULE_BEGIN
[debug] [monitor] sending monitor to loading packet
[debug] [monitor] waiting for loading packet
[debug] [ client] sending loading packet (size = 123)
[debug] [ client] sending loading packet (size = 49)
[debug] [monitor] received CFI_LOADING_SECTION_FUNCTION_ID
[debug] [ client] sending loading packet (size = 12)
[debug] [monitor] module has 8 function references
[debug] [ client] sending loading packet (size = 100)
[debug] [monitor] id= 0 main=NO init=NO fini=NO external=NO name=vulnerable
[debug] [monitor] id= 1 main=NO init=NO fini=NO external=YES name=strcpy
[debug] [ client] sending loading packet (size = 197)
[debug] [monitor] id= 2 main=YES init=NO fini=NO external=NO name=main
[debug] [ client] sending loading packet (size = 0)
[debug] [monitor] id= 3 main=NO init=NO fini=NO external=YES name=socket
[debug] [monitor] id= 4 main=NO init=NO fini=NO external=YES name=bind
[debug] [ client] sending loading packet (size = 0)
[debug] [monitor] id= 5 main=NO init=NO fini=NO external=YES name=listen
[debug] [monitor] id= 6 main=NO init=NO fini=NO external=YES name=accept
[debug] [ client] sending signal
[debug] [monitor] id= 7 main=NO init=NO fini=NO external=YES name=read
[debug] [ client] waiting for answer
[debug] [monitor] waiting for loading packet
[debug] [monitor] received CFI_LOADING_SECTION_FUNCTION_TRANSITION
[debug] [monitor] call from->to = 0 -> 1
[debug] [monitor] call from->to = 2 -> 0
[debug] [monitor] call from->to = 2 -> 3
[debug] [monitor] call from->to = 2 -> 4
[debug] [monitor] call from->to = 2 -> 5
[debug] [monitor] call from->to = 2 -> 6
[debug] [monitor] call from->to = 2 -> 7
[debug] [monitor] waiting for loading packet
[debug] [monitor] received CFI_LOADING_SECTION_BLOCK_TRANSITION
[debug] [monitor] waiting for loading packet
[debug] [monitor] received CFI_LOADING_SECTION_BLOCK_TRANSITION
[debug] [monitor] jump from->to = 0 -> 1
[debug] [monitor] jump from->to = 0 -> 2
[debug] [monitor] jump from->to = 2 -> 3
[debug] [monitor] jump from->to = 2 -> 4
[debug] [monitor] jump from->to = 4 -> 5
[debug] [monitor] jump from->to = 4 -> 6
[debug] [monitor] jump from->to = 6 -> 7
[debug] [monitor] jump from->to = 7 -> 8
[debug] [monitor] jump from->to = 7 -> 9
[debug] [monitor] jump from->to = 9 -> 7
[debug] [monitor] waiting for loading packet
[debug] [monitor] received CFI_LOADING_SECTION_BLOCK_IPD
[debug] [monitor] function= 0 block= 0 ipd= 0
[debug] [monitor] function= 2 block= 0 ipd= 0
[debug] [monitor] function= 2 block= 1 ipd= 0
[debug] [monitor] function= 2 block= 2 ipd= 0
[debug] [monitor] function= 2 block= 3 ipd= 0
[debug] [monitor] function= 2 block= 4 ipd= 0
[debug] [monitor] function= 2 block= 5 ipd= 0
[debug] [monitor] function= 2 block= 6 ipd= 7
[debug] [monitor] function= 2 block= 7 ipd= 8
[debug] [monitor] function= 2 block= 8 ipd= 0
[debug] [monitor] function= 2 block= 9 ipd= 7
[debug] [monitor] function= 2 block= 10 ipd= 0
[debug] [monitor] waiting for loading packet
[debug] [monitor] received CFI_LOADING_MODULE_END
[debug] [monitor] computing relocation of module id=0
[debug] [monitor] no relocation found for id=1 (name=strcpy)
[debug] [monitor] no relocation found for id=3 (name=socket)
[debug] [monitor] no relocation found for id=4 (name=bind)
[debug] [monitor] no relocation found for id=5 (name=listen)
[debug] [monitor] no relocation found for id=6 (name=accept)
[debug] [monitor] no relocation found for id=7 (name=read)
[debug] [monitor] 0 inits are expected
[debug] [monitor] waiting for new module
[debug] [monitor] waiting for loading packet
[debug] [monitor] received CFI_LOADING_TERMINATED
[debug] [monitor] computing relocation of module id=0
[debug] [monitor] no relocation found for id=1 (name=strcpy)
[error] [monitor] unresolved external function : strcpy
[error] [monitor] failed to load monitor data
[debug] [monitor] exits with status = 1
It seems like a linkage problem. Does anyone know how to fix this problem? Thanks!