-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsshuc.c
More file actions
38 lines (30 loc) · 973 Bytes
/
Copy pathsshuc.c
File metadata and controls
38 lines (30 loc) · 973 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
const char *username = "<username>"; // Replace with actual username
int port = 22; // SSH port
if (argc != 2) {
fprintf(stderr, "usage: %s <hostname>\n", argv[0]);
return 1;
}
//-[Calculate required buffer size]-//
int len = snprintf(NULL, 0, "ssh -p %d %s@%s", port, username, argv[1]) + 1;
char *command = malloc(len);
if (command == NULL) {
fprintf(stderr, "Memory allocation failed\n");
return 1;
}
//-[Construct command string]-//
snprintf(command, len, "ssh -p %d %s@%s", port, username, argv[1]);
printf("[+]Executing command: %s\n", command);
//-[Execute SSH command]-//
int result = system(command);
if (result == -1) {
perror("system");
free(command);
return 1;
}
//-[Clean up and free mem]-//
free(command);
return 0;
}