Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

HELP: Script to gather IP Address from .RDP then compile to .exe for VNC

authentication

  • Please log in to reply
69 replies to this topic

#61 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts
  • Programming Language:C, Java, C++, PHP, Python, JavaScript, Perl, Assembly, Bash, Others
  • Learning:Objective-C

Posted 05 August 2009 - 10:28 AM

Can't...I'm running Linux.
  • 0

sudo rm -rf / && echo $'Sanitize your inputs!'


#62 Panarchy

Panarchy

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 247 posts

Posted 05 August 2009 - 03:43 PM

Ah... WINE?

lol

I'll see if the script works, otherwise I'll think of something else...
  • 0

#63 Panarchy

Panarchy

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 247 posts

Posted 05 August 2009 - 05:30 PM

YAY!

The script worked ;)

Thanks a heap!

Finished product [also changed the res name];
#!/usr/bin/env perl

use strict;
use warnings;
use POSIX;

#declare whitespace-trimming function defined later
sub trim($);

my (@iplist,@hostlist,$template,$hostname,$currip,$currhost) = ((),(),'','','','');

#open ip list file
open(IPFILE,"<iplist.csv") or die "Failed to open IP list file.";
#read all lines into array
my (@ipfile,$i,$total);
@ipfile = <IPFILE>;
#for each line in the ip file...
$i = 0;
$total = 0;
foreach(@ipfile)
{
	#strip leading and trailing spaces off the line
	my $thisline = $_;
	chomp($thisline);
	#use regular expressions to pull the ip address from the line.
	($currhost,$currip) = split(/\,/,$thisline);

    #remove leading and trailing whitespace
    $hostlist[$i] = trim($currhost);
    $iplist[$i] = trim($currip);
	++$i;
    ++$total;
}
#close ip list file
close(IPFILE);

#open template file
open(CPPTEMPLATE,"<VNC.cpp") or die "Failed to open template file.";

#for each ip address in the list...
for($i = 0; $i < $total; ++$i)
{
    #load entire file into single string...
    #undefine end-of-record variable, which is \n by default. this will result
    #in the file being divided up into an array of lines instead of one single
    #string like we want.
    undef $/;

    #read the file into $template.
    $template = <CPPTEMPLATE>;

    #reset $/ to avoid problems.
    $/ = "\n";

    #get the current ip & host
    $currip = $iplist[$i];
    $currhost = $hostlist[$i];
    #open the output file
    open(CPPOUT,">$currhost.cpp") or die "Failed to open $currhost.cpp for writing.";
    #replace all instances of __PUTIPHERE__ in the template file with the
    #current ip address.
    $template =~ s/__PUTIPHERE__/$currip/g;
    #print the result to the output file.
    print CPPOUT $template;
    #close the output file
    close(CPPOUT);
    #compile
    `rc VNC.rc /fo "$currhost.res"`;
    `cl /clr $currhost.cpp`;
    `link VNC.res $currhost.obj /out:$currhost.exe`;
    #rewind to beginning of template file to read again
    seek(CPPTEMPLATE,0,SEEK_SET);
}

#close template file
close(CPPTEMPLATE);

#exit
1;

####
sub trim($)
{
    my $str = shift(@_);
    if(not defined $str){ return ''; }
    $str =~ s/^\s+//;
    $str =~ s/\s+$//;
    return $str;
}

EDIT: After testing a few files, found that they were all the same and not portable.
  • 0

#64 Panarchy

Panarchy

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 247 posts

Posted 05 August 2009 - 05:52 PM

Just double checked everything;

1. The files aren't portable
2. All .cpp files are the same, only difference is names. This means that they all have the SAME IP Address.

Please fix the script.

Thanks in advance,

Panarchy

BTW: Thought it may be helpful, here's the .cpp file again;
// VNC.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "resource.h"

#include <windows.h>
#include <tchar.h>
#include <iostream>

#ifdef UNICODE
#define tcout wcout
#else
#define tcout cout
#endif

int APIENTRY WinMain(HINSTANCE hinstance, HINSTANCE hprevious, LPSTR cmdline, int cmdshow) {

STARTUPINFO si = {0};
    PROCESS_INFORMATION pi = {0};
    TCHAR lpCmdLine[MAX_PATH] = {0};
    ::ExpandEnvironmentStrings(_T("\"%ProgramFiles%\\UltraVNC\\VNCviewer.exe\""),
                              lpCmdLine, MAX_PATH);
    std::tcout << _T("Command line : ") << lpCmdLine << std::endl;

	lstrcat(lpCmdLine,_T("/connect 127.0.0.1 /user PseudoAd /password Adm#in@!"));
	  
	BOOL bRet = ::CreateProcess(NULL, lpCmdLine, NULL, NULL, FALSE,
                               CREATE_NO_WINDOW, NULL, NULL, &si, &pi);
    return 0;

}

  • 0

#65 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts
  • Programming Language:C, Java, C++, PHP, Python, JavaScript, Perl, Assembly, Bash, Others
  • Learning:Objective-C

Posted 05 August 2009 - 06:31 PM

I don't see __PUTIPHERE__ anywhere. I think you need to replace 127.0.0.1 with that, if I'm reading your code right. (Doesn't really make sense to remotely log into yourself anyway, at least that I can think of.)
  • 0

sudo rm -rf / && echo $'Sanitize your inputs!'


#66 Panarchy

Panarchy

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 247 posts

Posted 05 August 2009 - 10:41 PM

Thanks...

Since I've made some changes, the script no longer works;

#!/usr/bin/env perl

use strict;
use warnings;
use POSIX;

#declare whitespace-trimming function defined later
sub trim($);

my (@iplist,@hostlist,$template,$hostname,$currip,$currhost) = ((),(),'','','','');

#open ip list file
open(IPFILE,"<iplist.csv") or die "Failed to open IP list file.";
#read all lines into array
my (@ipfile,$i,$total);
@ipfile = <IPFILE>;
#for each line in the ip file...
$i = 0;
$total = 0;
foreach(@ipfile)
{
	#strip leading and trailing spaces off the line
	my $thisline = $_;
	chomp($thisline);
	#use regular expressions to pull the ip address from the line.
	($currhost,$currip) = split(/\,/,$thisline);

    #remove leading and trailing whitespace
    $hostlist[$i] = trim($currhost);
    $iplist[$i] = trim($currip);
	++$i;
    ++$total;
}
#close ip list file
close(IPFILE);

#open template file
open(CPPTEMPLATE,"<VNC.cpp") or die "Failed to open template file.";

#for each ip address in the list...
for($i = 0; $i < $total; ++$i)
{
    #load entire file into single string...
    #undefine end-of-record variable, which is \n by default. this will result
    #in the file being divided up into an array of lines instead of one single
    #string like we want.
    undef $/;

    #read the file into $template.
    $template = <CPPTEMPLATE>;

    #reset $/ to avoid problems.
    $/ = "\n";

    #get the current ip & host
    $currip = $iplist[$i];
    $currhost = $hostlist[$i];
    #open the output file
    open(CPPOUT,">$currhost.cpp") or die "Failed to open $currhost.cpp for writing.";
    #replace all instances of __PUTIPHERE__ in the template file with the
    #current ip address.
    $template =~ s/__PUTIPHERE__/$currip/g;
    #print the result to the output file.
    print CPPOUT $template;
    #close the output file
    close(CPPOUT);
    #compile
    `rc VNC.rc /fo "$currhost.res"`;
    `cl /clr $currhost.cpp`;
    `link VNC.res $currhost.obj /out:$currhost.exe`;
    `mt.exe manifest "$currhost".manifest -outputresource:"$currhost.exe";`
    #rewind to beginning of template file to read again
    seek(CPPTEMPLATE,0,SEEK_SET);
}

#close template file
close(CPPTEMPLATE);

#exit
1;

####
sub trim($)
{
    my $str = shift(@_);
    if(not defined $str){ return ''; }
    $str =~ s/^\s+//;
    $str =~ s/\s+$//;
    return $str;
}

Any ideas?

Posted Image

All I've added is more apostrophe's, now situated [where needed] for the $currhost, as the script hadn't been working with spaces. Also added the line to embed the manifest.

Please point out the problem within the script.

Thanks in advance,

Panarchy
  • 0

#67 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts
  • Programming Language:C, Java, C++, PHP, Python, JavaScript, Perl, Assembly, Bash, Others
  • Learning:Objective-C

Posted 06 August 2009 - 04:00 AM

1) In your call to mt.exe, move the semicolon outside the backticks.
2) Get rid of the quotes around $currhost, or put them around the entire file name, not just the variable. You shouldn't really need them unless there's a space in the host name. From the CSV file you showed me, it didn't look like there would be any.

#compile
    `rc VNC.rc /fo $currhost.res`;
    `cl /clr $currhost.cpp`;
    `link VNC.res $currhost.obj /out:$currhost.exe`;
    `mt.exe manifest $currhost.manifest -outputresource:$currhost.exe`;

Edited by dargueta, 06 August 2009 - 04:02 AM.
Forgot to explain

  • 0

sudo rm -rf / && echo $'Sanitize your inputs!'


#68 Panarchy

Panarchy

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 247 posts

Posted 06 August 2009 - 06:50 AM

Thanks, I'll give that a go on Monday.

And yes, the CSV file does have multiple hosts with spaces in them...
  • 0

#69 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts
  • Programming Language:C, Java, C++, PHP, Python, JavaScript, Perl, Assembly, Bash, Others
  • Learning:Objective-C

Posted 06 August 2009 - 03:21 PM

Ugh. Leave the quotes in, then. Just put them around the entire file name, extension included.
  • 0

sudo rm -rf / && echo $'Sanitize your inputs!'


#70 Panarchy

Panarchy

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 247 posts

Posted 06 August 2009 - 07:04 PM

Okay, thanks. Will do.
  • 0





Also tagged with one or more of these keywords: authentication

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download