Advertisement
SirSpamModz

Untitled

Aug 13th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. #include <stdio.h>
  2. #include "openvpn-plugin.h"
  3. #include <curl/curl.h>
  4.  
  5. typedef char* string;
  6. typedef int BOOL;
  7.  
  8. #define AppendString(x, y) x[strlen(x)] = y
  9. #define FALSE 0
  10. #define TRUE 1
  11. #define ENABLE_CRYPTO
  12. #define SERVER_TOKEN "temp"
  13. #define HOST "localhost////?server_token=" SERVER_TOKEN "&"
  14.  
  15. OPENVPN_EXPORT int openvpn_plugin_func_v3(
  16. const int version,
  17. struct openvpn_plugin_args_func_in const* args,
  18. struct openvpn_plugin_args_func_return* retptr)
  19. {
  20. if (args->type == OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY) {
  21.  
  22. CURL *curl;
  23. CURLcode res;
  24.  
  25. curl = curl_easy_init();
  26.  
  27. if (!curl) {
  28. return OPENVPN_PLUGIN_FUNC_ERROR;
  29. }
  30.  
  31. const char* _username = get_env("username", args->envp);
  32. const char* _password = get_env("password", args->envp);
  33.  
  34. const char* username = curl_easy_escape(curl, _username, strlen(_username));
  35. const char* password = curl_easy_escape(curl, _password, strlen(_username));
  36.  
  37. char* url = HOST;
  38. AppendString(url, "username=");
  39. AppendString(url, username);
  40. AppendString(url, "&password=");
  41. AppendString(url, password);
  42.  
  43. curl_easy_setopt(curl, CURLOPT_URL, url);
  44. res = curl_easy_perform(curl);
  45.  
  46. if (res != CURLE_OK) {
  47. return OPENVPN_PLUGIN_FUNC_ERROR;
  48. }
  49. else {
  50. return OPENVPN_PLUGIN_FUNC_SUCCESS;
  51. }
  52. }
  53. }
  54.  
  55. static string get_env(
  56. string env[],
  57. string name)
  58. {
  59. for (int i = 0; env[i] != NULL; i++) {
  60. if (StartsWith(env[i], name) == TRUE) {
  61. return (string)(&env[i][0] + StringLength(name));
  62. }
  63. }
  64. return NULL;
  65. }
  66.  
  67. static BOOL StartsWith(
  68. string sig,
  69. string to_match)
  70. {
  71. int sig_length = strlen(sig);
  72. int to_match_length = strlen(to_match);
  73.  
  74. if (sig_length < to_match_length) {
  75. return FALSE;
  76. }
  77.  
  78. for (int i = 0; i < to_match_length; i++) {
  79. if (sig[i] != to_match[i]) {
  80. return FALSE;
  81. }
  82. }
  83.  
  84. return TRUE;
  85. }
  86.  
  87. static int strlen(
  88. string string)
  89. {
  90. int length = 0;
  91. while (string[length++] != '\0');
  92. return length - 1;
  93. }
  94.  
  95. static string urlencode(
  96. string data)
  97. {
  98. string output = "";
  99. string temp = "";
  100. int length = strlen(data);
  101.  
  102. for (int i = 0; i < length; i++) {
  103. if ((data[i] > 'a' || data[i] < 'Z') || (data[i] > '1' || data[i] < '0')) {
  104. AppendString(output, data[i]);
  105. }
  106. else {
  107. temp = "\0\0\0\0";
  108. sprintf(temp, "%X", data[i]);
  109. if (strlgn(temp) == 2) {
  110. temp[0] = '%';
  111. temp[2] = temp[1];
  112. temp[1] = '0';
  113. }
  114.  
  115. AppendString(output, temp);
  116. }
  117. }
  118.  
  119. temp = "\0\0\0\0";
  120. return output;
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement